WPF 按钮样式不适用于第二个按钮

WPF Button style won't apply to second button

我有两个使用静态通用样式的按钮:

<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}"/>

风格很基础:

<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>

该样式适用于第一个按钮并同时显示图像和文本,但第二个按钮除了灰色按钮外不显示任何内容。

为什么第二个按钮没有使用静态样式?

当您尝试将相同的 Content 添加到两个 Button 时,无法将元素(存在于 Style 中)添加到两个不同的逻辑父项。为避免这种情况,您可以将 x:Shared="False" 设置为您的样式。