具有分组单元格的XAML gridview listview

时间:2013-06-13 07:26:11

标签: xaml gridview merge

我在listview中有一个xaml gridview。 我的数据绑定发生在代码背后。 数据源是从sql填充的数据集。 数据集有6列。 '类型','NUM'和4行包含地址。 我想在gridview中的单个单元格中显示地址行,每行都在另一行之下。

XAML

<Grid x:Name="grid1">
<StackPanel>

        <ListView Name="listview1" Margin="10,10,10,10" IsTextSearchEnabled="True" TextSearch.TextPath="Addendum_Type" Height="400" BorderBrush="#FFA8CC7B">

        <ListView.View>

            <GridView ColumnHeaderToolTip="Addendum Master">

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Addendum_Type}" Header="TYPE" Width="150"/>

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Addendum_Number}" Header="NUM" Width="150"/>

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Line1}" Header="1" Width="150"/>

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Line2}" Header="2" Width="150"/>

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Line3}" Header="3" Width="150"/>

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Line4}" Header="4" Width="150"/>


            </GridView>

        </ListView.View>

    </ListView>

</StackPanel>
</Grid>

如何将这四行合并为一个单元格? This is what I want the Gridview to display

所以这就是我尝试过的          

        <ListView Name="listview1" Margin="10,10,10,10" IsTextSearchEnabled="True" TextSearch.TextPath="Addendum_Type" Height="400" BorderBrush="#FFA8CC7B">

        <ListView.View>

            <GridView ColumnHeaderToolTip="Addendum Master">

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Addendum_Type}" Header="TYPE" Width="150"/>

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Addendum_Number}" Header="NUM" Width="150"/>

                    <GridViewColumn Width="150">
                        <StackPanel>
                            <TextBlock Text="{Binding Path=Line1}" Grid.Column="1" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding Path=Line2}" Grid.Column="1" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding Path=Line3}" Grid.Column="1" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding Path=Line4}" Grid.Column="1" TextWrapping="Wrap"/>
                        </StackPanel>
                    </GridViewColumn>

            </GridView>

        </ListView.View>

    </ListView>

</StackPanel>
</Grid>

但这只是将gridview看作是

enter image description here

1 个答案:

答案 0 :(得分:0)

我这样做是对的。

<ListView Name="listview1" Margin="10,10,10,10" IsTextSearchEnabled="True" TextSearch.TextPath="Addendum_Type" Height="400" BorderBrush="#FFA8CC7B">

        <ListView.View>

            <GridView ColumnHeaderToolTip="Addendum Master">

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Addendum_Type}" Header="TYPE" Width="150"/>

                    <GridViewColumn DisplayMemberBinding="{Binding Path=Addendum_Number}" Header="NUM" Width="150"/>

                    <GridViewColumn Width="500">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <Label Content="{Binding Path=Line1}"></Label>
                                    <Label Content="{Binding Path=Line2}"></Label>
                                    <Label Content="{Binding Path=Line3}"></Label>
                                    <Label Content="{Binding Path=Line4}"></Label>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>

                    </GridViewColumn>

            </GridView>

        </ListView.View>