我<ItemsControl>
为我的<custom:Pack>
列表创建了视图:
<ItemsControl ItemsSource="{Binding List}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:ShelfPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="local:ShelfPanel.Exact" Value="{Binding Exact}"/>
// Default ZIndex is set 1, when Active it should be higher, hence will be over others.
<Setter Property="Panel.ZIndex" Value="1" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<custom:Pack Background="Red" Width="150" Height="150" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="MyStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)" To="Yellow" Duration="0:0:0.5" />
</Storyboard>
</VisualState>
<VisualState x:Name="Active">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)" To="Green" Duration="0:0:0.5" />
// How to animate ZIndex on ContentPresenter ?
<Int32Animation Storyboard.TargetProperty="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentPresenter}}, Path=(Panel.ZIndex)}" To="3" Duration="00:00:0.2"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</custom:Pack>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<local:ShelfPanel>
的设计方式<custom:Pack>
相互重叠。现在,当您选择一个<custom:Pack>
时,它的状态更改为Active
,对象应该超过所有其他状态。
现在我得到了预期:
您必须为&#34; System.Windows.Media.Animation.Int32动画指定TargetProperty
要实现这一点,我需要在ContentPresenter上设置ZInedx,该怎么做?