❔ How to define a button style for setting content as image?

I'm not sure if this is a bug or a quirk with setting content on button (or I'm just not doing things correctly). What I'm trying to do is have a set of button styles for commonly used buttons in a plugin I'm creating (it's not an app, hence the use of pack uri's). What i have is: In my Styles Resource Dictionary i have the following (the IconButton Style, just sets background and border values)
<Style
x:Key="AddButton"
BasedOn="{StaticResource IconButton}"
TargetType="Button">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Content">
<Setter.Value>
<Image Source="pack://application:,,,/Example;component/Assets/add.png" />
</Setter.Value>
</Setter>
</Style>
<Style
x:Key="AddButton"
BasedOn="{StaticResource IconButton}"
TargetType="Button">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Content">
<Setter.Value>
<Image Source="pack://application:,,,/Example;component/Assets/add.png" />
</Setter.Value>
</Setter>
</Style>
Then in my user control I have:
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource AddButton}" />
<Button Style="{StaticResource AddButton}" />
<Button Style="{StaticResource AddButton}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource AddButton}" />
<Button Style="{StaticResource AddButton}" />
<Button Style="{StaticResource AddButton}" />
</StackPanel>
The behaviour I see is that the content is only set for the last button. This occurs no matter how many or if the buttons exist in different parents, the last one is the only one ever to have any content (i.e. image). See attached image. Can anyone help? When i set the content manually it works fine, but I have to repeat the uri which is painful....
5 Replies
JakenVeina
JakenVeina2y ago
have a peek at those buttons in the Live Property Explorer I don't see why that wouldn't work
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
SoggyBottomBoy
SoggyBottomBoyOP2y ago
Yer I can't figure out for the life of me why this would not work. Tried a bunch of things. Live preview has the extract same display (i.e. missing images) too. I've still had no success...
JakenVeina
JakenVeina2y ago
what do you see in the Live Property Explorer?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server