1

I have two buttons that use a static common style:

<Button x:Name="BtnCreate" Height="22" Width="150" Style="{StaticResource Style.Button.Trash}"/>
<Button x:Name="aefae" Height="22" Width="150" Style="{StaticResource Style.Button.Trash}"/>

The style is very basic:

<Style TargetType="Button" x:Key="Style.Button.Trash" 
       BasedOn="{StaticResource {x:Type Button}}">
    <Setter Property="Content">
        <Setter.Value>
        <StackPanel Orientation="Horizontal" >
            <Image Source="{StaticResource Image.Trash}" Width="22" Height="22"/>
            <Label Content="Save" VerticalAlignment="Center" Height="26" />
        </StackPanel>
        </Setter.Value>
    </Setter>
</Style>

The style applies to the first button and display both the image an the text however the second button does not display anything except a grey button.

Why does the second button not use the static style?

David R
  • 14,711
  • 7
  • 54
  • 72
Michael Edwards
  • 6,308
  • 6
  • 44
  • 75
  • 1
    Is the resource image set shared? (x:Shared="false") – Babbillumpa Jul 12 '18 at 14:23
  • Are those buttons as shown here one under other or you have them in different files? – Rafal Jul 12 '18 at 14:24
  • Possible duplicate of [In WPF, can I share the same image resource between 2 buttons](https://stackoverflow.com/questions/14110068/in-wpf-can-i-share-the-same-image-resource-between-2-buttons) – Babbillumpa Jul 12 '18 at 14:30

1 Answers1

1

As you're trying to add the same Content to two Buttons, elements (present in Style) cannot be added to two different Logical Parents. To avoid this, you can set x:Shared="False" to your style.

dhilmathy
  • 2,800
  • 2
  • 21
  • 29