我真的试图找到解决方案,但我失败了。所以我在单独的 xaml 文件中有 ResourceDictionary,在另一个 cs 文件中有 Control 类。这是 xaml 代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1" x:Class="Control1">
<Style TargetType="{x:Type local:Control1}">
<Setter Property="GridColor" Value="Red"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Control1}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid x:Name="PART_Grid" Background="{TemplateBinding GridColor}"
Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
<Button Grid.Column="1" x:Name ="PART_Button" Width="50" Height="50"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="GridColor" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
在 cs 文件中,我更改了IsChecked事件处理OnMouseEnter程序OnMouseLeave。它工作正常。问题是,例如,当我更改事件处理GridColor程序OnButtonClick时,它会更改,但之后触发器设置器不起作用(但另一个设置器仍然可以正常工作)。没有例外,输出中没有消息。我错过了什么?
波斯汪
相关分类