I've got this working:
<Button Content="{StaticResource SaveImage}" />
But now I want to make the button a little more complicated
<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"/>
A resource is an object that can be reused in different places in your app. Examples of resources include brushes and styles. This overview describes how to use resources in Extensible Application Markup Language (XAML). You can also create and access resources by using code.
A StaticResource will be resolved and assigned to the property during the loading of the XAML which occurs before the application is actually run. It will only be assigned once and any changes to resource dictionary ignored.
Dynamic ResourceThe concept is the same as data binding in WPF if the value of the bound property is changed. So is the value on UI. Change XAML as follows: added a new button. Also, add 2 resources in the code behind.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With