有没有办法在同一个 canvas 中设置不同 ItemsControl 的 ZIndex
Is there a way to set the ZIndex of different ItemsControl within the same canvas
我试图在 canvas 中设置不同 ItemsControl 的 ZIndex,最初我这样做效果很好。以下每个集合都按预期组织。
<ItemsControl ItemsSource="{Binding AllPoints.PointsObjects}" Panel.ZIndex={Binding ZIndex}>
<ItemsControl ItemsSource="{Binding AllTracks.TrackObjects}" Panel.ZIndex={Binding ZIndex}>
但是我需要能够单独更改每个 ItemsControl 中每个项目的 ZIndexes。所以我将 ZIndex 绑定移动到每个单独的对象并尝试使用 ItemsControl.ItemContainerStyle 设置 ZIndex。但是集合并没有按预期的顺序出现。
<ItemsControl ItemsSource="{Binding AllPoints.PointsObjects}">
<ItemsControl.Resources>
<!--Resource dictionary template-->
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
<ItemsControl ItemsSource="{Binding AllTracks.TrackObjects}">
<ItemsControl.Resources>
<!--Resource dictionary template-->
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
我是否只需要创建一个 ItemsControl,或者是否可以通过使用 ItemsControl.ItemContainerStyle link 个不同的 ItemsControl 的 ZIndexes?
跟随 Clemens 对我的回答 post 这就是我的问题的解决方案。 Windows.Resources.
内
<Window.Resources>
<CollectionViewSource x:Key="Points" Source="{Binding AllPoints.PointsObjects}"/>
<CollectionViewSource x:Key="Tracks" Source="{Binding AllTracks.TrackObjects}"/>
<CompositeCollection x:Key="CombinedCollection">
<CollectionContainer Collection="{Binding Source={StaticResource Points}}" />
<CollectionContainer Collection="{Binding Source={StaticResource Tracks}}" />
</CompositeCollection>
</Window.Resources>
并在 Canvas.
内
<Canvas>
<ItemsControl ItemsSource="{StaticResource CombinedCollection}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Panel.ZIndex" Value="{Binding ZIndex}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Canvas>
我试图在 canvas 中设置不同 ItemsControl 的 ZIndex,最初我这样做效果很好。以下每个集合都按预期组织。
<ItemsControl ItemsSource="{Binding AllPoints.PointsObjects}" Panel.ZIndex={Binding ZIndex}>
<ItemsControl ItemsSource="{Binding AllTracks.TrackObjects}" Panel.ZIndex={Binding ZIndex}>
但是我需要能够单独更改每个 ItemsControl 中每个项目的 ZIndexes。所以我将 ZIndex 绑定移动到每个单独的对象并尝试使用 ItemsControl.ItemContainerStyle 设置 ZIndex。但是集合并没有按预期的顺序出现。
<ItemsControl ItemsSource="{Binding AllPoints.PointsObjects}">
<ItemsControl.Resources>
<!--Resource dictionary template-->
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
<ItemsControl ItemsSource="{Binding AllTracks.TrackObjects}">
<ItemsControl.Resources>
<!--Resource dictionary template-->
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
我是否只需要创建一个 ItemsControl,或者是否可以通过使用 ItemsControl.ItemContainerStyle link 个不同的 ItemsControl 的 ZIndexes?
跟随 Clemens 对我的回答 post 这就是我的问题的解决方案。 Windows.Resources.
内 <Window.Resources>
<CollectionViewSource x:Key="Points" Source="{Binding AllPoints.PointsObjects}"/>
<CollectionViewSource x:Key="Tracks" Source="{Binding AllTracks.TrackObjects}"/>
<CompositeCollection x:Key="CombinedCollection">
<CollectionContainer Collection="{Binding Source={StaticResource Points}}" />
<CollectionContainer Collection="{Binding Source={StaticResource Tracks}}" />
</CompositeCollection>
</Window.Resources>
并在 Canvas.
内<Canvas>
<ItemsControl ItemsSource="{StaticResource CombinedCollection}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Panel.ZIndex" Value="{Binding ZIndex}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Canvas>