c# - WPF ListView - 具有 1 个相同结构的 2 个维度

标签 c# wpf listview gridview binding

我们正在处理 ListView (C# WPF),但我们没有发现如何绑定(bind)列中的项目列表,每个项目本身都包含一个具有相同列的项目列表。

让我们用一个例子来说明这一点:

Exemple of our objective !

我们得到了一个带有参数(名称等)的对象的可观察集合,每个对象都包含另一个具有相同参数的对象的可观察集合(除了它们没有列表)。所以我们想在 ListView 中列出它,但我们不知道怎么做!

我们对 ListView 的了解还不足以实现这个结构,有什么建议吗?

提前致谢

最佳答案

我认为最好的方法是:

XAML:

<Window.Resources>
<DataTemplate x:Key="gridViewSecondCellTemplate1">
            <StackPanel Width="100">
                <TextBlock Text="{Binding Content}" FontSize="15" />
            </StackPanel>
</DataTemplate>

        <DataTemplate x:Key="gridViewCellTemplate1">
            <StackPanel Width="100">
                <TextBlock Text="{Binding Title}" FontSize="15" />
                <ListView ItemsSource="{Binding MySecondSource}>
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="{Binding Subtitle}" CellTemplate="{StaticResource gridViewSecondCellTemplate1}"/>
                    </GridView>
                </ListView.View>
                </ListView>
            </StackPanel>
        </DataTemplate>
</Window.Resources>

    <ListView ItemsSource="{Binding MySource}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Col 1" Width="100" CellTemplate="{StaticResource gridViewCellTemplate1}"/>
                    </GridView>
                </ListView.View>
            </ListView>

我没有尝试这段代码。试试看,如果可以的话告诉我。

关于c# - WPF ListView - 具有 1 个相同结构的 2 个维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22760720/

相关文章:

c# - rc1.final 中的 User.Identity 中不存在 getUserId

c# - 如何同时启用 , 和 .然后将其格式化为 .适用于所有文化中的 DataGridColumn?

c# - WPF:ComboBox F4 键未在 KeyDown 事件中触发

android - 从可绘制对象加载图像时列表滚动变慢

c# - 属性错误: An attribute argument must be a constant expression, 属性参数类型的typeof表达式或数组创建表达式

wpf - WCF PollingDuplexHttpBinding 与 Silverlight 客户端超时和错误

c# - 另一个程序集中的 MVVM 行为

android - Android ListView 的替代 UI

android - 从 ListView 中删除并在android中删除后刷新 ListView 数据

c# - 使用另一个字节列表/数组计算字节列表/数组中的出现次数