【问题标题】:Binding a CollectionViewSource to ObservableCollection将 CollectionViewSource 绑定到 ObservableCollection
【发布时间】:2012-04-08 20:06:34
【问题描述】:

无法绑定 CollectionViewSource

DocProps 是公共属性

public ObservableCollection<DocProp> DocProps1

DataContext 是自我

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

这行得通

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

我无法连接 CollectionViewSource 进行排序 这甚至没有得到 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 绑定到公共属性?

谢谢

【问题讨论】:

    标签: .net binding collectionviewsource


    【解决方案1】:

    它会这样工作:

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

    这篇文章XAML Binding to a CollectionViewSource property on a ViewModel对这种行为有一些解释

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      • 2019-10-02
      • 1970-01-01
      • 2013-09-07
      • 2019-02-24
      • 2011-05-20
      相关资源
      最近更新 更多