WPF控件开发思路 [英] WPF control develop idea
问题描述
好的,我想创建一个类似于 Stackpanel
的控件,左边是 TextBlock
,类似于:
OK, I want to create a control that is like a Stackpanel
with TextBlock
on the left, something like:
TextBlock
需要可编辑.所以,问题是我需要从谁那里继承才能做到这一点,因为不能从 Stackpanel
继承?
The TextBlock
need to be editable. So, the question is from whom I need to inherit to make that since cannot from Stackpanel
?
推荐答案
这基本上是一个 HeaderedItemsControl
带有自定义 模板
.
That is basically a HeaderedItemsControl
with a custom Template
.
模板可以是一个带有两列的 Grid
,其中一个包含一个旋转的 ContentPresenter
,它绑定到标题属性,在右边你会有一个 ItemsPresenter
用于项目.
The template could be a Grid
with two columns, one containing a rotated ContentPresenter
which is bound to the header properties, on the right you would have an ItemsPresenter
for the items.
例如
<Style TargetType="HeaderedItemsControl"> <!-- Implicitly applied -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="HeaderedItemsControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ContentPresenter ContentSource="Header">
<ContentPresenter.LayoutTransform>
<RotateTransform Angle="-90"/>
</ContentPresenter.LayoutTransform>
</ContentPresenter>
<ItemsPresenter Grid.Column="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<HeaderedItemsControl Header="Lorem Ipsum" ItemsSource="ABCDEF"/>
这篇关于WPF控件开发思路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!