这是情况......在顶层,我有一个TabControl.TabControl中的每个页面都包含一个ListBox:
<TabControl>
<TabItem Header="item 1">
<ListBox>
<ListBoxItem>sub item 1</ListBoxItem>
<ListBoxItem>sub item 2</ListBoxItem>
<ListBoxItem>sub item 3</ListBoxItem>
</ListBox>
</TabItem>
<TabItem Header="item 2">
<ListBox>
<ListBoxItem>sub item 1</ListBoxItem>
<ListBoxItem>sub item 2</ListBoxItem>
</ListBox>
</TabItem>
</TabControl>
Run Code Online (Sandbox Code Playgroud)
ListBoxes有一个水平方向的StackPanel作为它们的ListTemplate:
<Style TargetType="ListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VisibleChanged="onStackPanelVisibilityChange"
Loaded="onStackPanelLoaded"
VerticalAlignment="Center" HorizontalAlignment="Center" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
您会注意到我在堆栈面板上有一些事件处理程序.这些是为堆栈面板中的项目设置动画,因此它们会依次淡入视图.事件处理程序实现为:
void onStackPanelLoaded(object sender, RoutedEventArgs e)
{
StackPanel panel = sender as StackPanel;
applySubItemAnimations(panel);
}
void onStackPanelVisibilityChange(object sender, DependencyPropertyChangedEventArgs e)
{
StackPanel panel = sender as StackPanel;
if (panel.IsVisible)
{
applySubItemAnimations(panel);
} …Run Code Online (Sandbox Code Playgroud)