ollectionViewSource绑定到Observable

ollectionViewSource绑定到Observable

本文介绍了将CollectionViewSource绑定到ObservableCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法绑定CollectionViewSource

Cannot bind the CollectionViewSource

DocProps是公共财产

DocProps is a public property

public ObservableCollection<DocProp> DocProps1

DataContext是自我

DataContext is self

DataContext="{Binding RelativeSource={RelativeSource self}}"

这有效

<ListBox Grid.Row="0" Grid.Column="0" ItemsSource="{Binding Path=DocProps1}">

我无法连接CollectionViewSource进行排序这甚至没有得到DocProps1

I cannot wire up a CollectionViewSource to sortThis does not even get DocProps1

    <ListBox Grid.Row="0" Grid.Column="0">
        <ListBox.ItemsSource>
            <Binding>
                <Binding.Source>
                    <CollectionViewSource Source="{Binding Path=DocProps1}">
                        <CollectionViewSource.SortDescriptions>
                            <scm:SortDescription PropertyName="Name" />
                        </CollectionViewSource.SortDescriptions>
                    </CollectionViewSource>
                </Binding.Source>
            </Binding>
        </ListBox.ItemsSource>

如何将CollectionViewSource绑定到公共属性?

How do I bind a CollectionViewSource to a public property?

谢谢

推荐答案

它将以这种方式工作:

<ListBox ItemsSource="{Binding}">
  <ListBox.DataContext>
    <CollectionViewSource Source="{Binding Path=DocProps1}">
    </CollectionViewSource>
  </ListBox.DataContext>
</ListBox>

本文将XAML绑定到ViewModel上的CollectionViewSource属性对这种行为有一些解释

This article XAML Binding to a CollectionViewSource property on a ViewModel has some explanations of this behaviour

这篇关于将CollectionViewSource绑定到ObservableCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:39
查看更多