在ListView控件的GridView的缩进第一列 [英] Indent first column in GridView of ListView

查看:273
本文介绍了在ListView控件的GridView的缩进第一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以列表视图中创建一个gridview。
有2级节点的,我想缩进的子节点。
因此,我已经设置了&LT保证金;项目presenter>
结果看起来pretty好,但在第二和第三列也被缩进,并根据其标题列不对齐。
任何想法缩进只有第一列,但不休息列?

I have created a gridview by using list view. There is 2 level of nodes and I would like to indent the child node. Therefore, I have set the margin in the <ItemPresenter>. The result looks pretty good but the second and the third column also been indent and not align according to its header column. Any idea to indent only the first column but not the rest column?

XAML

<ListView Name="listViewResult" Margin="10,231,0,-299" BorderBrush="#FF000000" BorderThickness="1" >
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Name" Width="280" DisplayMemberBinding="{Binding GrandChildNodeData}" />
                        <GridViewColumn Header="Date/ Time" Width="160" DisplayMemberBinding="{Binding Time}" />
                        <GridViewColumn Header="State" Width="160" DisplayMemberBinding="{Binding State}" />
                    </GridView>
                </ListView.View>

                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style TargetType="{x:Type GroupItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <Expander IsExpanded="True">
                                                <Expander.Header>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" VerticalAlignment="Bottom" />
                                                        <TextBlock Text="{Binding ItemCount}" Foreground="Silver" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
                                                        <TextBlock Text=" item(s)" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
                                                    </StackPanel>
                                                </Expander.Header>
                                                <ItemsPresenter Margin="20,0,0,0" />
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                </ListView.GroupStyle>
            </ListView>

结果

推荐答案

这个问题已经由Magnus在已经回答了这个<一个href=\"https://social.msdn.microsoft.com/Forums/vstudio/en-US/23cb51bb-337c-4faf-a25f-760236c78f90/indent-first-column-in-gridview-of-listview?forum=wpf\"相对=nofollow>论坛

This question has been answered by Magnus in this forum

你要设置整个GroupItem的保证金,应定义为第一列CellTemplate并设置页边距在那里。

"You are setting the Margin of the entire GroupItem. You should define a CellTemplate for the first column and set the Margins in there:"

<ListView.View>
        <GridView>
          <GridViewColumn Header="Name" Width="120">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding Name}" Margin="20 0 0 0"/>
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
          <GridViewColumn Header="Date/ Time" Width="160" DisplayMemberBinding="{Binding Time}" />
          <GridViewColumn Header="State" Width="160" DisplayMemberBinding="{Binding State}" />
        </GridView>
      </ListView.View>
        <ListView.GroupStyle>
        <GroupStyle>
          <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate>
                    <Expander IsExpanded="True">
                      <Expander.Header>
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="{Binding Name}" FontWeight="Bold" VerticalAlignment="Bottom" />
                          <TextBlock Text="{Binding ItemCount}" Foreground="Silver" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
                          <TextBlock Text=" item(s)" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
                        </StackPanel>
                      </Expander.Header>
                      <ItemsPresenter />
                    </Expander>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </GroupStyle.ContainerStyle>
        </GroupStyle>
      </ListView.GroupStyle>

这篇关于在ListView控件的GridView的缩进第一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆