Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 来自MVVM的CollectionViewSource_C#_Xaml - Fatal编程技术网

C# 来自MVVM的CollectionViewSource

C# 来自MVVM的CollectionViewSource,c#,xaml,C#,Xaml,如果我有这样的想法: <UserControl.Resources> <app:People x:Key="vm"></app:People> <--nvm this for now... <CollectionViewSource x:Name="cvs" IsSourceGrouped="True"

如果我有这样的想法:

<UserControl.Resources>
        <app:People x:Key="vm"></app:People> <--nvm this for now...

        <CollectionViewSource   x:Name="cvs"
                                IsSourceGrouped="True"
                                ItemsPath="Items" />
    </UserControl.Resources>
这不起作用,因为此处无法解析CV。
希望我在这里足够清楚。谢谢大家!

你有没有考虑过把简历发给ctor?谢谢!我不知道如何将CV传递给ctor,您能告诉我如何传递吗?@artm:CollectionViewSource是ICollectionView的XAML代理,不应该在视图模型中使用它。@丹尼斯我想的是类似于public PeopleVmICollectionView cvs的东西:这个{cvs.Source=groupedPeople;}不幸的是,我无法以这种方式访问Source。。。
private IList<Person> people;
private IList<Group<object, Person>> groupedPeople;

public People()
{
    this.InitializeComponent();
    people = Person.CreatePeople(200).ToList();
    groupedPeople = (from person in people
                     group person by person.City into g
                     orderby g.Key
                     select new Group<object, Person>
                     {
                         Key = g.Key.ToString(),
                         Items = g.ToList()
                     }).ToList();
    cvs.Source = groupedPeople;
}
public PeopleVm()
        {
            people = Person.CreatePeople(200).ToList();
            groupedPeople = (from person in people
                             group person by person.City into g
                             orderby g.Key
                             select new Group<object, Person>
                             {
                                 Key = g.Key.ToString(),
                                 Items = g.ToList()
                             }).ToList();
            cvs.Source = groupedPeople;
        }