c# - 来自 ItemsControl 的 Panel.ZIndex 在 WPF .NET Core 应用程序中的 Canvas 上不起作用
问题描述
我在用户控件中有一个画布。在画布内,我有一个 Image 和一个 ItemsControl。例如: <ItemsControl ... /> 项目控件如下所示:
<ItemsControl
x:Name="itmZoneShapes"
ItemsSource="{Binding LastSelectedZone.PredefinedSelectedLogicalZones}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Path=RectangleCanvasLeft}" />
<Setter Property="Canvas.Top" Value="{Binding Path=RectangleCanvasTop}" />
<Setter Property="Panel.ZIndex" Value="{Binding Path=RectangleCanvasZIndex}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle
StrokeThickness="2"
Stroke="Black"
Tag="{Binding Path=RectangleName}"
Width="{Binding Path=RectangleWidth}"
Height="{Binding Path=RectangleHeight}"
RadiusX="{Binding Path=RectangleRadiusX}"
RadiusY="{Binding Path=RectangleRadiusY}">
<Rectangle.Fill>
<SolidColorBrush
Color="{Binding Path=RectangleBackgroundColor,
UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
Opacity="0.4"/>
</Rectangle.Fill>
<Rectangle.Clip>
<RectangleGeometry Rect="{Binding Path=RectangleClip}"/>
</Rectangle.Clip>
</Rectangle>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
问题是,绑定的 Panel.ZIndex 以某种方式仅在 ItemsPanelTemplate 标记的 Canvas 中起作用。
我想要的是能够为 itemscontrol 内的每个元素设置 Panel.ZIndex 并在图像上方或图像下方显示矩形(基于 Panel.ZIndex )。现在,我只能更改 ItemsControl Panel.ZIndex,但问题是数据模板中的所有项目都将具有相同的 ZIndex。
是否有可能为 ItemsControl 中的每个项目绑定 Panel.ZIndex 并在 UI 中正确可见?
解决方案
推荐阅读
- reporting-services - SSRS组合饼图
- javascript - 获取一个按钮以响应响应 div 的大小
- python - PCA后的sklearn cosine_similarity内存错误
- python - 为什么 roc_auc 在 sklearn 中会产生奇怪的结果?
- node.js - node.js 中 Scope 和 for.each 的问题
- spartacus-storefront - 如何设置斯巴达克斯店面的默认语言?
- vega-lite - Vega-lite:为什么图形宽度会影响轴标签的格式?
- apache - 使用自定义 OpenSSL 编译 Apache 后,“此版本的 mod_ssl 是针对较新的库编译的”
- python - 进行迁移的问题 Django
- rust - 为什么 Rust 允许对值及其引用进行相同的方法调用?