• 全部
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm&WPF
  • C#开发新技术
  • 问答

wpf新手 求解样式触发器问题

不ok个男人 2021-03-11 04:50:41
控件如下:
<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>

样式如下:
<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变更却没效果,求大神答疑
...全文
96 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
哎呀哇 03-16
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border Background="{TemplateBinding Background}" BorderThickness="0" > <ContentControl Height="30" Width="35" HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding Content}" Background="{TemplateBinding Background}" /> </Border> </ControlTemplate> </Setter.Value> </Setter>
回复
发帖
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2021-03-11 04:50
社区公告

让您成为最强悍的C#开发者