我想扩展ItemsPanel
,以便我可以显示一个“分层”视觉结构,其中我有一个已知大小和大量覆盖的“框架”,类似于制图或插图应用程序。
我遇到的问题是找出如何组合事物以使一切按预期工作。到目前为止我做了什么:
- 创建了一个继承自的控件
ItemsControl
; - 在控件内部,放置一个
Viewbox
包含一个ItemsPresenter
- 在控件的资源中,创建了一个针对其自身类型的样式,将 设置
ItemsPanel
为由Canvas
.
所以我希望,在 Live Tree Inspection 下,我应该在嵌套结构中看到:
- LayerContainer(我的控件的类名)
- 视图框
- 项目演示者
- 帆布
- 项目1
- 项目2
- 视图框
相反,我看到的是:
- 层容器
- 边界
- 项目演示者
- 帆布
- 视框
- 项目1
- 项目2
- 边界
所以问题是 ViewBox 包含在 Canvas 中,与渲染的项目一起。
那么我的问题是:如何以嵌套顺序为 ItemsPresenter->Viewbox->Canvas->Items 的方式构建我的 LayerContainer 控件?
这是我的控件(名称实际上不是LayerContainer
)
<ItemsControl x:Class="Miotec.PressureMapping.UserControls.BaroLayerContainer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Miotec.PressureMapping.UserControls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ItemsControl.Resources>
<Style TargetType="local:BaroLayerContainer">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Canvas Width="{Binding Parametros.Colunas}"
Height="{Binding Parametros.Linhas}"
IsItemsHost="True"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.Resources>
<Viewbox Stretch="Uniform" x:Name="container">
<ItemsPresenter
Width="{Binding ActualWidth, ElementName=container}"
Height="{Binding ActualHeight, ElementName=container}"/>
</Viewbox>
</ItemsControl>