...">

WPF XAML syntax for including a resource as an xml element, not as a property

This works for me:

<Button Content="{StaticResource SaveImage}" /> 

But now I want to make the button a little harder

  <Button> <Button.Content> <StackPanel Orientation="Horizontal" > {StaticResource SaveImage} <!-- WHAT GOES HERE?? --> <Label>Save</Label> </StackPanel> </Button.Content> </Button> 

How to place an image resource in an xml tree, and not just assign it to a property of the Button class?

Note. A resource is defined as:

 <Image x:Key="SaveImage" x:Shared="False" Source="Save.png" Height="16" Width="16"/> 
+6
syntax wpf xaml
source share
3 answers

You can directly use StaticResource . Try it like this:

 <Button> <Button.Content> <StackPanel Orientation="Horizontal" > <StaticResource ResourceKey="SaveImage"/> <Label>Save</Label> </StackPanel> </Button.Content> </Button> 
+17
source share
 <Image Source="{StaticResource SaveImage}"/> 
0
source share

The easiest way to go in most of these situations is to simply use content management inside

 <Button> <ContentControl Content="{StaticResource whatever}" /> </Button> 
0
source share

All Articles