WPF XAML syntax for including resource as xml element rather than as property
I've got this working:
<Button Content="{StaticResource SaveImage}" />
But now I want to make the button a little more complic开发者_如何学Pythonated
<Button>
<Button.Content>
<StackPanel Orientation="Horizontal" >
{StaticResource SaveImage} <!-- WHAT GOES HERE?? -->
<Label>Save</Label>
</StackPanel>
</Button.Content>
</Button>
How do I place the image resource in the xml tree, rather than just assigning it to a property to the Button class?
Note, the resource is defined like:
<Image x:Key="SaveImage" x:Shared="False" Source="Save.png" Height="16" Width="16"/>
You can use a StaticResource
directly. Try it like this
<Button>
<Button.Content>
<StackPanel Orientation="Horizontal" >
<StaticResource ResourceKey="SaveImage"/>
<Label>Save</Label>
</StackPanel>
</Button.Content>
</Button>
<Image Source="{StaticResource SaveImage}"/>
The easiest way to go in most of these situations is just to use content control inside
<Button>
<ContentControl Content="{StaticResource whatever}" />
</Button>
精彩评论