控件代码如下[Asm] 纯文本查看 复制代码 <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" MinWidth="100" > <!--添加按钮-->
<Button Style="{StaticResource TitelButtonStyle}" >
<Grid>
<Image Source="添加.png" HorizontalAlignment="Left" RenderOptions.BitmapScalingMode="Fant" />
<TextBlock Margin="0,1,0,0" Foreground="White" Text="添加" HorizontalAlignment="Right" Width="28 " />
</Grid>
</Button>
<Grid Width="1" Height="20" Background="White" Opacity="0.5" Margin="10,0,0,0"/>
<!--选项按钮-->
<Button Style="{StaticResource TitelButtonStyle}" >
<Grid>
<Image Source="齿轮.png" HorizontalAlignment="Left" RenderOptions.BitmapScalingMode="Fant" />
<TextBlock Margin="0,1,0,0" Text="选项" HorizontalAlignment="Right" Width="28 " />
</Grid>
</Button>
<Grid Width="1" Height="20" Background="White" Opacity="0.5" Margin="10,0,0,0"/>
<!--关闭按钮-->
<Button Style="{StaticResource CloseButton}">
<Grid Height="17" Width="35">
<Image Source="关闭.png" RenderOptions.BitmapScalingMode="Fant" />
</Grid>
</Button>
</StackPanel> 样式如下:
[Asm] 纯文本查看 复制代码 <Style x:Key="CloseButton" TargetType="Button">
<Setter Property="Opacity" Value="0.5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent" BorderThickness="0" >
<ContentControl Height="30" Width="35" HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding Content}" Background="{TemplateBinding Background}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#ff0000"/>
<Setter Property="Opacity" Value="1" />
</Trigger>
</Style.Triggers>
</Style>
关闭按钮应用的样式中,鼠标悬停触发器更改了两个属性,Opacity更改了可以生效,Background变更却没效果,求大神答疑 |