WPF 求助 给我的这段代码生成的按钮添加点击时按钮背景颜色改变的效果
在触发器里修改和添加事件的方法已经试过,但是并没有实现变色的效果代码片段:<Window.Resources><Stylex:Key="ButtonStyle1"Targ...
在触发器里修改和添加事件的方法已经试过,但是并没有实现变色的效果
代码片段:
<Window.Resources>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Ellipse RenderTransformOrigin="0.5,0.5" Stroke="#FFD8A924" StrokeThickness="5">
<Ellipse.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFF3CB12" Offset="0"/>
<GradientStop Color="#FFFBB065" Offset="1"/>
<GradientStop Color="#FFE5CA4B" Offset="0.552"/>
</LinearGradientBrush>
</Ellipse.Fill>
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90.332"/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="更正"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources> 展开
代码片段:
<Window.Resources>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Ellipse RenderTransformOrigin="0.5,0.5" Stroke="#FFD8A924" StrokeThickness="5">
<Ellipse.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFF3CB12" Offset="0"/>
<GradientStop Color="#FFFBB065" Offset="1"/>
<GradientStop Color="#FFE5CA4B" Offset="0.552"/>
</LinearGradientBrush>
</Ellipse.Fill>
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90.332"/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="更正"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources> 展开
1个回答
展开全部
你的Trigger怎么没有Setter节点呢?
更多追问追答
追问
我之前加了 但是没有效果 被我删掉了
我是这么加的:
追答
试了一下,如果把Grid命名为g,下面的代码可以让背景色变化,不过貌似你应该把TargetName换成你的Ellipse才好,但你的填充样式就得自己写了
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="g" Property="Background" Value="Blue"/>
</Trigger>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询