如何将HeaderedItemsControl项显示为列

时间:2015-12-15 19:54:25

标签: c# wpf xaml

我正在使用HeaderedItemsControl类编写Costum DataGridView,并且我想将我的控件的项目对齐为列,如下所示:

enter image description here

而不是实际出现:

实际上

enter image description here

这是我的XAML代码:

<Style TargetType="{x:Type local:DataGridView}">
    <Setter Property="HeaderTemplate">
        <Setter.Value>
            <DataTemplate>
                <TextBlock Background="Red" Text="{TemplateBinding Content}"/>
            </DataTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:DataGridView}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>

                    <ContentPresenter Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}"/>
                    <ItemsPresenter Grid.Row="1"/>

                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

感谢阅读

0 个答案:

没有答案