【发布时间】:2015-03-08 11:28:22
【问题描述】:
我是 WPF 和 XAML 的新手。这个问题很直接。
我想在按下按钮时将触发器中椭圆的 Fill 属性从默认的“#597E0000”修改为“Black”。显然我没有正确访问该属性,因为我无法编译它并在下面代码中指示的行上获得以下内容:
“无法在样式设置器上设置 TargetName 属性。第 16 行”
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="ExitButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate x:Name="exitButtonTemplate" TargetType="Button">
<Grid>
<Ellipse x:Name="exitButtonEllipse" Fill="#597E0000"/>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="exitButtonEllipse" Property="Fill" Value="Black" /> <!-- error -->
</Trigger>
</Style.Triggers>
</Style>
【问题讨论】: