Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 鼠标悬停不触发动画_Wpf_Xaml - Fatal编程技术网

Wpf 鼠标悬停不触发动画

Wpf 鼠标悬停不触发动画,wpf,xaml,Wpf,Xaml,我有一个小问题,除了当我打开鼠标时,当我离开时,背景会改变,但是当我把它放在上面时,它不会从白色变为我的颜色 <!-- ComboBox: Item Triggers --> <Style TargetType="{x:Type ComboBoxItem}"> <Setter Property="Template"> <Setter.Value> <Control

我有一个小问题,除了当我打开鼠标时,当我离开时,背景会改变,但是当我把它放在上面时,它不会从白色变为我的颜色

<!-- ComboBox: Item Triggers -->
    <Style TargetType="{x:Type ComboBoxItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBoxItem}">

                    <Border Name="Border" CornerRadius="0" BorderThickness="0" Focusable="False" BorderBrush="Transparent" Background="White">
                        <Grid  VerticalAlignment="Center" HorizontalAlignment="Center">
                            <ContentPresenter VerticalAlignment="Center" />
                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Foreground" Value="White" />
                        </Trigger>
                        <EventTrigger RoutedEvent="MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation From="White" To="#52b0ca" Duration="0:0:0.5" Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="MouseLeave">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation From="#52b0ca" To="White" Duration="0:0:0.5" Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

看起来有什么东西在处理
鼠标事件,所以我建议使用,而不是:


<ControlTemplate TargetType="{x:Type ComboBoxItem}">
   <Border Name="Border" CornerRadius="0" BorderThickness="0" Focusable="False" BorderBrush="Transparent" Background="White">
      <Grid  VerticalAlignment="Center" HorizontalAlignment="Center">
         <ContentPresenter VerticalAlignment="Center" />
      </Grid>
   </Border>
   <ControlTemplate.Triggers>
      <Trigger Property="IsMouseOver" Value="true">
         <Setter Property="Foreground" Value="White" />
         <Trigger.EnterActions>
            <BeginStoryboard>
               <Storyboard>
                  <ColorAnimation From="White" To="#52b0ca" Duration="0:0:0.5" Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color"/>
               </Storyboard>
            </BeginStoryboard>
         </Trigger.EnterActions>
         <Trigger.ExitActions>
            <BeginStoryboard>
               <Storyboard>
                  <ColorAnimation From="#52b0ca" To="White" Duration="0:0:0.5" Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color"/>
               </Storyboard>
            </BeginStoryboard>
         </Trigger.ExitActions>
      </Trigger>
   </ControlTemplate.Triggers>
</ControlTemplate>