In App.xaml I have this code:
<Application.Resources>
<ResourceDictionary>
<Color x:Key="Yellow">#ffd966</Color>
</ResourceDictionary>
</Application.Resources>
and in C# I have this code:
public Color BackgroundColor
{
get { return IsSelected ? Color.Yellow : Color.White; }
}
And I would like to change Color.Yellow with color from App.xaml. How can I reference color from App.xaml in C#?
xaml. cs is the code-behind page for MainPage. xaml. It's where you add your app logic and event handlers. Together these two files define a new class called MainPage , which inherits from Page, in the HelloWorld namespace.
XAML allows developers to define user interfaces in Xamarin. Forms applications using markup rather than code. XAML is never required in a Xamarin. Forms program, but it is often more succinct and more visually coherent than equivalent code, and potentially toolable.
isSelected ? (Color) Application.Current.Resources["Yellow"] : Color.White;
I think Conversion Color.FromHex() is not needed as you are defining resource as a color. Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With