wpf - 有没有办法在同一个画布内设置不同 ItemsControl 的 ZIndex
问题描述
我正在尝试在画布中设置不同 ItemsControls 的 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 来链接不同的 ItemsControl 的 ZIndexes?
解决方案
在 Clemens 对我的帖子的回答之后,这是我问题的解决方案。在 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>
<ItemsControl ItemsSource="{StaticResource CombinedCollection}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Panel.ZIndex" Value="{Binding ZIndex}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Canvas>
推荐阅读
- http - 谷歌云函数请求被中止,因为没有可用的实例
- python - 使用 .predict() 方法时,sklearn 中的管道对象是否会转换测试数据?
- javascript - 在 Redux 中将商品添加到购物车
- python - 部署到heroku的django应用程序中的unixODBC 0100错误
- python - 使用列表值获取 dict 的最大值和最小值
- python - 如何将文件发送到接受python烧瓶中表单数据的post方法,以及如何在被调用方法中检索文件和其他字段?
- flutter - 没有为“FirebaseAuth”类型定义吸气剂“onAuthStateChanged”
- java - 如何在 Java Spring 中排除某些 HTTP 请求(例如 /health Endpoint)
- java - Java SSL/TLS(没有可用的身份验证方案)
- google-apps-script - 非连续范围