Forum Xamarin.Forms

Setting Color in XAML from hex string declared in code

Hi!) Sorry perhaps for a nub question but

How can be Color set in App.xaml Resources with a string that is declared in code like :

       <Color x:FactoryMethod="FromHex" x:Key="TitleColor">


      public const string TitleColor = "#97cd75";

So that something like

       <Color>{x:Static MyColors.TitleColor}</Color>

can be acheived

Thanx! in advance;)


  • GeraldVersluisGeraldVersluis NLUniversity ✭✭✭✭

    I think you might want to take a look at the documentation here!

  • Thanks but as you could guess I did) I have dynamic styles and can do some hacks in code in Resources dictionary after InitialiseComponent but that's not an option, at least for now :D

    Also btw - why? do I get this:(

    'Xamarin.Forms.Color' is declared in another module and needs to be imported

    when my namespace imports do look like this

  • VitaliyHnatyk.5863VitaliyHnatyk.5863 UAMember
    edited April 2016

    Umm perhaps I should ask - why

    <Color><x:Static Member="MyColors.TitleColor"/></Color> 


    <Color><xString><x:Static Member="MyColors.TitleColor"/></x:String></Color>

    compiles and doesn't throw any exceptions, nor it does what I suppose it should do - initializing the color with Transparent instead.

  • JerzyPiechowiakJerzyPiechowiak USMember ✭✭

    Do you have working solution for this? I've occured the same error today, when I turned on xaml compilation.

Sign In or Register to comment.