我的按钮样式不会在MouseOver上显示我的背景图像

时间:2013-02-22 12:00:53

标签: c# wpf xaml styles

我为这样的按钮创建了一个样式

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

非常感谢:)

1 个答案:

答案 0 :(得分:1)

由于您将<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>