我正在使用 ICollectionView 过滤我的数据列表。但是当我尝试过滤数据时,RadListBox 什么也没有显示。这是我为此尝试的代码。
XAML:
<Window.Resources>
<local:MyList x:Key="MyData"/>
<CollectionViewSource x:Key="MyCollection" Source="{Binding ClassTwos, Source={StaticResource MyData}}"/>
</Window.Resources>
<telerik:RadListBox x:Name="ListTwo" ItemsSource="{Binding Source={StaticResource MyCollection}}" Margin="184,78,0,0" Width="94" Height="175" DisplayMemberPath="Name"/>
C# :
public class MyList
{
public ObservableCollection<TestClassTwo> ClassTwos { get; set; }
public MyList()
{
ClassTwos = new ObservableCollection<TestClassTwo>
{
new TestClassTwo{Name = "Sound"},
new TestClassTwo{Name = "Samsung"},
new TestClassTwo{Name = "yahoo"}
};
}
}
public MainWindow()
{
InitializeComponent();
var collectionView = (this.ListTwo.ItemsSource as ICollectionView);
if (collectionView != null)
{
collectionView.Filter = p => ((TestClassTwo)p).Name == "s";
}
}