PDA

View Full Version : Image Brush reference in a resource dictionary



Andrew24
June 17th, 2009, 11:04 PM
I'm building a WPF app in Blend 3 which has an "indicator light" that I want to switch to an ON state when a game controller is detected. I am using a canvas object with the background set to an image brush resource defined in a resource dictionary.


<Canvas x:Name="ControllerIndicator" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="13" Height="13" Background="{DynamicResource Light_off}" Margin="0,0,303,35"/>


When my app detects the presence of a controller I want to programatically set the background of the canvas to another image brush resource I have defined in my resource dictionary; something like this:

(C#)

ControllerIndicator.Background = (ResourceDictionary.name???).Light_on;

Can I do it this way? If so, does anyone know the syntax?

Or, do I need to create the brush(s) dynamically in C#?

Any suggestions much appreciated.

Andrew24
June 19th, 2009, 01:33 AM
Found a solution:


ControllerIndicator.Background = (Brush)this.FindResource("Light_on");

cheers,
Andrew

kirupa
June 19th, 2009, 02:09 AM
Ah - good old FindResource. Glad you figured it out :)