我已经为类似的按钮创建了一个样式
<Style TargetType="{x:Type Button}" x:Key="BoutonRessources">
<Setter Property="Width" Value="18" />
<Setter Property="Margin" Value="-1,0,-2,0" />
<Setter Property="ToolTip" Value="Clear" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="BoutonToolbarSelected.png"/>
</Setter.Value>
</Setter>
<Setter Property="Height" Value="22"/>
<Setter Property="Width" Value="32"/>
</Trigger>
</Style.Triggers>
</Style>
我的按钮出现在我的屏幕上,但当鼠标放在按钮上时,它不会显示我的"BoutonToolbarSelected.png"。你知道为什么吗?
以下是我如何调用我的按钮:
<Button Style="{StaticResource BoutonRessources}" >
<Image Source= "xRtDiva_XWPF_TBR_PREMIER.PNG_IMAGES.png" Height="18"/>
</Button>
非常感谢:)
因为您将<Image Source= "xRtDiva_XWPF_TBR_PREMIER.PNG_IMAGES.png" Height="18"/>
设置为按钮的内容,所以背景将隐藏在它后面。
您可以将触发器更改为:
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="BoutonToolbarSelected.png"/>
</Setter.Value>
</Setter>
<Setter Property="Height" Value="22"/>
<Setter Property="Width" Value="32"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="xRtDiva_XWPF_TBR_PREMIER.PNG_IMAGES.png"/>
</Setter.Value>
</Setter>
<Setter Property="Height" Value="18"/>
</Trigger>
</Style.Triggers>