Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Store App - XAML - C# - Access ThemeResource in code

I have a Styles.xaml file where I have declared various colours and styles.

    <SolidColorBrush x:Key="MyColour" Color="#FFFF411E"/>

I want to access this in code, as I have control and I want to bind the background colour to a Property in an object. This easily done, however, the object is created from the response to a server call and the property could be one of many colours. I could define the colour in code, but as I use the same colour for other controls defined in XAML I dont really want to define the same colour twice in the application. So I want a way to be able to access the SolidColorBrush brush in code to be able to use it.

Any idea's how to do this?

like image 379
Ne0 Avatar asked Mar 19 '23 08:03

Ne0


1 Answers

Try this..

 Application.Current.Resources[ "MyColour" ] as SolidColorBrush 
like image 172
bit Avatar answered Apr 24 '23 02:04

bit