0

好吧,我很不走运,因为我做的很多事情都会以某种方式破坏设计师(其他问题

当我在数据网格视图中使用集合时,我可以在设计器中看到我生成的所有虚拟内容行,但是当我添加集合视图源以对数据进行分组时,这将停止工作。然后整个集合仅在运行时显示。

这是 WPF 设计器的另一个问题吗?

复制代码:

看法:

<Window x:Class="CollectionViewSourceDesignerBreak.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:collectionViewSourceDesignerBreak="clr-namespace:CollectionViewSourceDesignerBreak" >
    <Window.DataContext>
        <collectionViewSourceDesignerBreak:ViewModel />
    </Window.DataContext>

    <Window.Resources>
        <CollectionViewSource Source="{Binding Entries}" x:Key="Cvs">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Name"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>

    </Window.Resources>


    <DataGrid ItemsSource="{Binding Entries}" AutoGenerateColumns="True">
    <!--<DataGrid ItemsSource="{Binding Source={StaticResource Cvs}}" AutoGenerateColumns="True">-->

    </DataGrid>
</Window>

虚拟视图模型:

using System.Collections.ObjectModel;

namespace CollectionViewSourceDesignerBreak
{
    public class VMData
    {
        public string Name { get; set; }
        public string MoreInfo { get; set; }

    }
    public class ViewModel
    {
        private ObservableCollection<VMData> _entries = new ObservableCollection<VMData>();
        public ObservableCollection<VMData> Entries
        {
            get { return _entries; }
            set { _entries = value; }
        }

        public ViewModel()
        {
            Entries.Add(new VMData{Name="A", MoreInfo = "Some text"});
            Entries.Add(new VMData{Name="B", MoreInfo = "More text"});
            Entries.Add(new VMData{Name="A", MoreInfo = "Other text"});
        }
    }
}

注释 Cvs 行输入和其他输出,内容在设计器中消失。

4

0 回答 0