2009-07-27 23 views
1

Je définissent actuellement l'arrière-plan pour un contrôle utilisateur comme ceci:Comment affecter une ressource imagebrush dynamique à l'arrière-plan d'une pile dans le code?

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

Comment puis-je déplacer ce à code-behind, par exemple:

PSEUDO-CODE:

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

Répondre

2

permettez-moi de répondre à celui-ci, je l'ai fait fonctionner comme ceci:

dans le code:

StackPanel sp = new StackPanel(); 
sp.SetResourceReference(StackPanel.BackgroundProperty, "LeftMenuBackgroundImageBrush"); 

ressources:

<ImageBrush x:Key="LeftMenuBackgroundImageBrush" 
    ImageSource="{DynamicResource LeftMenuBackgroundImage}"/> 

<ImageSource x:Key="LeftMenuBackgroundImage">Images/LeftMenuBackground.jpg</ImageSource>