我想在WPF应用程序中链接两个CollectionViewSource
。 有什么办法可以让以下事情发挥作用?链接CollectionViewSource
MainWindow.xaml.cs:
using System.Collections.Generic;
using System.Linq;
using System.Windows;
namespace ChainingCollectionViewSource
{
public partial class MainWindow : Window
{
public IEnumerable<int> Items => Enumerable.Range(0, 10);
public MainWindow()
{
DataContext = this;
InitializeComponent();
}
}
}
MainWindow.xaml:
<Window x:Class="ChainingCollectionViewSource.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<CollectionViewSource x:Key="ItemsViewA"
Source="{Binding Items}" />
<CollectionViewSource x:Key="ItemsViewB"
Source="{Binding Source={StaticResource ItemsViewA}}" />
</Window.Resources>
<ListBox ItemsSource="{Binding Source={StaticResource ItemsViewB}}" />
</Window>
你能解释一下为什么你正在尝试做的这个?也许有更好的方法去做呢? – Kelly
这基本上是一个更复杂的对象树的摘录。设想控制A通过CollectionViewSource过滤其数据并将其传递给控件B的ItemsSource。它的工作原理是控件B将通过将其ItemsSource绑定到其自己的CollectionViewSource来尝试执行自己的过滤,分组或排序。 –