我正在尝试在下面的样式中计算 ControlTemplate.Triggers,但我还没有弄清楚如何找到命名的 Ellipse 和 Path 属性。
比如IsMouseOver时,改变Ellipse的背景。什么是找到 Ellipse 的好方法,以便我可以按照设置此样式的方式设置 Fill 属性?有没有更好的方法来布置它?
干杯,
贝里尔
<Style x:Key="CloseCrossToggleButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid Background="Transparent">
<!-- The background of the button, as an ellipse. -->
<Ellipse x:Name="theEllipse" />
<!-- A path that renders a cross. -->
<Path x:Name="theCross"...
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<ContentPresenter x:Name="theContent"/>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Ellipse.Fill" Value="{StaticResource HoverBackgroundBrush}" />
<Setter Property="Path.Stroke" Value="{StaticResource HoverForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
好的,正在工作
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid Background="Transparent">
<!-- The background of the button, as an ellipse. -->
<Ellipse x:Name="theEllipse" />
<!-- A path that renders a cross. -->
<Path x:Name="theCross"
...
</Path>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="theEllipse" Property="Fill" Value="{StaticResource HoverBackgroundBrush}" />
<Setter TargetName="theCross" Property="Stroke" Value="{StaticResource HoverForegroundBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="theEllipse" Property="Fill" Value="{StaticResource PressedBackgroundBrush}" />
<Setter TargetName="theEllipse" Property="Stroke" Value="{StaticResource PressedBorderBrush}" />
<Setter TargetName="theCross" Property="Stroke" Value="{StaticResource PressedForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>