WPF control develop idea

故事扮演 提交于 2019-12-11 04:41:32

问题


OK, I want to create a control that is like a Stackpanel with TextBlock on the left, something like:

The TextBlock need to be editable. So, the question is from whom I need to inherit to make that since cannot from Stackpanel?


回答1:


That is basically a HeaderedItemsControl with a custom Template.

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.

e.g.

<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"/>


来源:https://stackoverflow.com/questions/9957757/wpf-control-develop-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!