如何根据以下要求在XAML中创建WPF复选框控件模板?

如何根据以下要求在XAML中创建WPF复选框控件模板?,wpf,xaml,checkbox,triggers,controltemplate,Wpf,Xaml,Checkbox,Triggers,Controltemplate,我想要一个在未选中状态下不可见的复选框。取消选中时,将鼠标悬停在其上将使其动画透明度设置为0.3 当鼠标指针离开复选框时,如果仍未选中该复选框,则其动画将恢复为0透明度 选中时,它将处于完全可见状态,即透明度=1 到目前为止,我所有的尝试都没有成功,我想这是因为鼠标悬停的规则。当选中“我的复选框”时,鼠标悬停仍会导致淡入0.3,在鼠标离开时,它将不可见。 我尝试使用触发器、多触发器和VSM,但我不知道如何在没有冲突的情况下编写我想要的行为 代码: 这里是触发器方法。它经历了这么多的迭代,我甚至不

我想要一个在未选中状态下不可见的复选框。取消选中时,将鼠标悬停在其上将使其动画透明度设置为0.3

当鼠标指针离开复选框时,如果仍未选中该复选框,则其动画将恢复为0透明度

选中时,它将处于完全可见状态,即透明度=1

到目前为止,我所有的尝试都没有成功,我想这是因为鼠标悬停的规则。当选中“我的复选框”时,鼠标悬停仍会导致淡入0.3,在鼠标离开时,它将不可见。 我尝试使用触发器、多触发器和VSM,但我不知道如何在没有冲突的情况下编写我想要的行为

代码: 这里是触发器方法。它经历了这么多的迭代,我甚至不记得这是否是我最初的方法。 我也有一个VSM方法,只要说你是否也需要这个方法的代码

控制模板(我取了MSDN中提供的样本,并对其进行了修改)


声明

<CheckBox Width="100" Height="100">Hello</CheckBox>
你好
检查触发器的位置:将IsChecked触发器放在IsMouseOver触发器下。

好吧,我刚刚采用了一种有点可怕的解决方法。将鼠标移到stuff上可处理虚拟背景路径/图像,而选中和取消选中可处理主路径/图像

Kaxaml代码转储:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
    <Grid.Resources>
        <Style x:Key="{x:Type CheckBox}"
               TargetType="{x:Type CheckBox}">
          <Setter Property="SnapsToDevicePixels"
                  Value="true" />
          <Setter Property="OverridesDefaultStyle"
                  Value="true" />
          <Setter Property="FocusVisualStyle"
                  Value="{DynamicResource CheckBoxFocusVisual}" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type CheckBox}">
                <BulletDecorator Background="Transparent">
                  <BulletDecorator.Bullet>
                    <Border x:Name="Border"
                            Width="80"
                            Height="80"
                            CornerRadius="0"
                            BorderThickness="1">


                      <Grid>
                      <Path Visibility="Visible"
                              Width="100"
                              Height="100"
                              x:Name="Dummy"
                              SnapsToDevicePixels="False"
                              StrokeThickness="9"
                              Opacity="0"
          Data="M 0 30 C 2,29 10,30 14,39 M 15,40 C 5,31 55,10 45,20 ">
                          <Path.Stroke>
                            <SolidColorBrush Color="#FF224502" />
                          </Path.Stroke>
                        </Path>                                            
                        <Path Visibility="Visible"
                              Width="100"
                              Height="100"
                              x:Name="CheckBorder"
                              SnapsToDevicePixels="False"
                              StrokeThickness="9"
                              Opacity="0"
          Data="M 0 30 C 2,29 10,30 14,39 M 15,40 C 5,31 55,10 45,20 ">
                          <Path.Stroke>
                            <SolidColorBrush Color="Black" />
                          </Path.Stroke>
                        </Path>                           
                        <Path Visibility="Visible"
                              Width="100"
                              Height="100"
                              x:Name="CheckMark"
                              Opacity="0"
                              SnapsToDevicePixels="False"
                              StrokeThickness="6"
          Data="M 1 30 C 2,29 10,30 14,39 M 15,39 C 5,31 55,10 45,20 ">
                          <Path.Stroke>
                            <SolidColorBrush Color="#FF0C9D0C" />
                          </Path.Stroke>
                        </Path>
                        <Path Visibility="Collapsed"
                              Width="100"
                              Height="100"
                              x:Name="InderminateMark"
                              SnapsToDevicePixels="False"
                              StrokeThickness="5"
                              Data="M 0 0 L 50 50">
                          <Path.Stroke>
                            <SolidColorBrush Color="{DynamicResource GlyphColor}" />
                          </Path.Stroke>
                        </Path>
                      </Grid>
                    </Border>
                  </BulletDecorator.Bullet>
                </BulletDecorator>

                <ControlTemplate.Triggers>

                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True"/>                        
                            <Condition Property="IsChecked" Value="False"/>
                        </MultiTrigger.Conditions>

                        <MultiTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Dummy" To="0.3" Duration="0:0:0.1"/>
                                </Storyboard>
                            </BeginStoryboard>                        
                        </MultiTrigger.EnterActions>
                        <MultiTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Dummy" To="0" Duration="0:0:0.1"/>
                                </Storyboard>
                            </BeginStoryboard>                        
                        </MultiTrigger.ExitActions>                        

                    </MultiTrigger>



                     <Trigger Property="IsChecked" Value="True"> 
                        <Setter TargetName="CheckBorder" Property="Opacity" Value="1"/>
                        <Setter TargetName="CheckMark" Property="Opacity" Value="1"/>
                     </Trigger>



                     <Trigger Property="IsChecked" Value="False"> 
                        <Setter TargetName="CheckBorder" Property="Opacity" Value="0"/>
                        <Setter TargetName="CheckMark" Property="Opacity" Value="0"/>
                     </Trigger>                    


                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>



    </Grid.Resources>


        <CheckBox Width="100" Height="100">Hello</CheckBox>
  </Grid>
</Page>

你好

请显示您迄今为止尝试过的代码。我认为情况就是这样。如果您想分析,我现在已经发布了代码。
<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
    <Grid.Resources>
        <Style x:Key="{x:Type CheckBox}"
               TargetType="{x:Type CheckBox}">
          <Setter Property="SnapsToDevicePixels"
                  Value="true" />
          <Setter Property="OverridesDefaultStyle"
                  Value="true" />
          <Setter Property="FocusVisualStyle"
                  Value="{DynamicResource CheckBoxFocusVisual}" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type CheckBox}">
                <BulletDecorator Background="Transparent">
                  <BulletDecorator.Bullet>
                    <Border x:Name="Border"
                            Width="80"
                            Height="80"
                            CornerRadius="0"
                            BorderThickness="1">


                      <Grid>
                      <Path Visibility="Visible"
                              Width="100"
                              Height="100"
                              x:Name="Dummy"
                              SnapsToDevicePixels="False"
                              StrokeThickness="9"
                              Opacity="0"
          Data="M 0 30 C 2,29 10,30 14,39 M 15,40 C 5,31 55,10 45,20 ">
                          <Path.Stroke>
                            <SolidColorBrush Color="#FF224502" />
                          </Path.Stroke>
                        </Path>                                            
                        <Path Visibility="Visible"
                              Width="100"
                              Height="100"
                              x:Name="CheckBorder"
                              SnapsToDevicePixels="False"
                              StrokeThickness="9"
                              Opacity="0"
          Data="M 0 30 C 2,29 10,30 14,39 M 15,40 C 5,31 55,10 45,20 ">
                          <Path.Stroke>
                            <SolidColorBrush Color="Black" />
                          </Path.Stroke>
                        </Path>                           
                        <Path Visibility="Visible"
                              Width="100"
                              Height="100"
                              x:Name="CheckMark"
                              Opacity="0"
                              SnapsToDevicePixels="False"
                              StrokeThickness="6"
          Data="M 1 30 C 2,29 10,30 14,39 M 15,39 C 5,31 55,10 45,20 ">
                          <Path.Stroke>
                            <SolidColorBrush Color="#FF0C9D0C" />
                          </Path.Stroke>
                        </Path>
                        <Path Visibility="Collapsed"
                              Width="100"
                              Height="100"
                              x:Name="InderminateMark"
                              SnapsToDevicePixels="False"
                              StrokeThickness="5"
                              Data="M 0 0 L 50 50">
                          <Path.Stroke>
                            <SolidColorBrush Color="{DynamicResource GlyphColor}" />
                          </Path.Stroke>
                        </Path>
                      </Grid>
                    </Border>
                  </BulletDecorator.Bullet>
                </BulletDecorator>

                <ControlTemplate.Triggers>

                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True"/>                        
                            <Condition Property="IsChecked" Value="False"/>
                        </MultiTrigger.Conditions>

                        <MultiTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Dummy" To="0.3" Duration="0:0:0.1"/>
                                </Storyboard>
                            </BeginStoryboard>                        
                        </MultiTrigger.EnterActions>
                        <MultiTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Dummy" To="0" Duration="0:0:0.1"/>
                                </Storyboard>
                            </BeginStoryboard>                        
                        </MultiTrigger.ExitActions>                        

                    </MultiTrigger>



                     <Trigger Property="IsChecked" Value="True"> 
                        <Setter TargetName="CheckBorder" Property="Opacity" Value="1"/>
                        <Setter TargetName="CheckMark" Property="Opacity" Value="1"/>
                     </Trigger>



                     <Trigger Property="IsChecked" Value="False"> 
                        <Setter TargetName="CheckBorder" Property="Opacity" Value="0"/>
                        <Setter TargetName="CheckMark" Property="Opacity" Value="0"/>
                     </Trigger>                    


                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>



    </Grid.Resources>


        <CheckBox Width="100" Height="100">Hello</CheckBox>
  </Grid>
</Page>