0

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

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

非常感谢 :)

4

1 回答 1

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>
于 2013-02-22T12:26:33.533 回答