我遇到了关于动画执行两次的问题,请检查代码:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ListView x:Name="lstHandled" Grid.Column="0" Visibility="Visible">
<ListViewItem>Jimmy</ListViewItem>
<ListViewItem>Jimmy</ListViewItem>
<ListViewItem>Jimmy</ListViewItem>
<ListViewItem>Jimmy</ListViewItem>
<ListViewItem>Jimmy</ListViewItem>
<ListViewItem>Jimmy</ListViewItem>
<ListViewItem>Jimmy</ListViewItem>
<ListViewItem>Jimmy</ListViewItem>
<ListView.Triggers>
<EventTrigger RoutedEvent="ListView.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation
Storyboard.TargetName="spAll"
Storyboard.TargetProperty="(StackPanel.Margin)"
From="-100,0,0,0" To="0,0,0,0"
AutoReverse="False"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ListView.Triggers>
</ListView>
<StackPanel x:Name="spAll" Grid.Column="0" Width="100" Margin="-100,0,0,0" Orientation="Horizontal">
<ListView x:Name="Handled">
<ListViewItem>Hello</ListViewItem>
<ListViewItem>Hello</ListViewItem>
<ListViewItem>Hello</ListViewItem>
<ListViewItem>Hello</ListViewItem>
<ListViewItem>Hello</ListViewItem>
<ListViewItem>Hello</ListViewItem>
<ListViewItem>Hello</ListViewItem>
<ListViewItem>Hello</ListViewItem>
</ListView>
<ListView x:Name="UnHandled">
<ListViewItem>World</ListViewItem>
<ListViewItem>World</ListViewItem>
<ListViewItem>World</ListViewItem>
<ListViewItem>World</ListViewItem>
<ListViewItem>World</ListViewItem>
<ListViewItem>World</ListViewItem>
<ListViewItem>World</ListViewItem>
<ListViewItem>World</ListViewItem>
</ListView>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="StackPanel.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation
Storyboard.TargetName="spAll"
Storyboard.TargetProperty="(StackPanel.Margin)"
From="0,0,0,0" To="-100,0,0,0"
AutoReverse="False"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</Grid>
当鼠标离开“spAll”StackPanel时。它为ListView触发了Mouse Enter事件。如何避免这个问题?
非常感谢!
答案 0 :(得分:0)
它们都在同一个网格列中,因此它们重叠,因此输入/离开事件:)在UI中将它们分开。