1

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

xml

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

如何将这四行合并为一个单元格? 这就是我希望 Gridview 显示的内容

所以这就是我尝试过的

        <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看起来像

在此处输入图像描述

4

1 回答 1

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>
于 2013-06-13T09:24:23.423 回答