How to assign a dynamic imagebrush resource to a stackpanel's background in code?

Posted by Edward Tanguay on Stack Overflow See other posts from Stack Overflow or by Edward Tanguay
Published on 2009-07-27T11:35:36Z Indexed on 2010/06/01 23:03 UTC
Read the original article Hit count: 327

Filed under:
|
|

I currently define the background for a user control like this:

<UserControl.Background>
    <ImageBrush ImageSource="{DynamicResource LeftMenuBackgroundImage}" />
</UserControl.Background>

How can I move this to code-behind, e.g.:

PSEUDO-CODE:

StackPanel sp = new StackPanel();
sp.Background = new ImageBrush(DynamicResource.GetResourceName("LeftMenuBackgroundImage"));

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml