wpf mvvm在datagrid中显示可观察的集合 [英] wpf mvvm displaying observable collection in datagrid

查看:87
本文介绍了wpf mvvm在datagrid中显示可观察的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 DataGrid

ItemsCollectionA

ItemsCollectionA, ItemsCollectionB and ItemsCollectionC are all ObservableCollections.

我有一个数据网格:

<DataGrid ItemsSource="{Binding Path=itemscollectionA}" HeadersVisibility="All" />

这将以网格格式显示所有属性,但 ItemsCollectionB ItemsCollectionC 显示为(集合)。

This displays all properties in grid format but the ItemsCollectionB and ItemsCollectionC are appearing as (collection).

如何获取 ItemsCollectionB ItemsCollectionC 来向下和向外扩展网格同时显示它们的属性

How can I get ItemsCollectionB and ItemsCollectionC to expand the grid downward and out to show their properties as well

推荐答案

好吧,看来datagrid完全是我在这里需要的错。我制作了一个列表框的堆栈面板,并将itemsource设置为每个绑定,并且显示良好

Ok it seems like datagrid was entirely the wrong thing I needed here. I made a stackpanel of listbox with the itemssource set to each binding and it's displaying fine

<StackPanel Background="white" HorizontalAlignment="Stretch"  Margin="0">
        <ListBox Background="white" x:Name="BetsListBox"  VerticalAlignment="Stretch" BorderThickness="0" 
                     ItemsSource="{Binding Path=ItemsCollectionA}" Margin="0" Width="Auto" HorizontalAlignment="Stretch" >
            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#F0F0F0"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#F0F0F0"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel >
                        <ListBox ItemsSource="{Binding Path=ItemsCollectionB}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlockText="{Binding Path=varA}" />
                                        <TextBlockText="{Binding Path=varB}" />
                                        <TextBlockText="{Binding Path=varC}" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                        <ListBox BorderThickness="0" ItemsSource="{Binding Path=ItemsCollectionC}" >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel  Orientation="Horizontal" >
                                        <TextBlock Text="{Binding Path=VarA}" ToolTip="{Binding Name}"/>
                                        <TextBlock Text="{Binding Path=VarB}" ToolTip="{Binding Name}"/>
                                        <TextBlock Text="{Binding Path=VarC}" ToolTip="{Binding Name}"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox >
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>

这篇关于wpf mvvm在datagrid中显示可观察的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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