我有一个文本框,应该过滤我的listview,但它不起作用。 数据是正确的,但它不会刷新列表。
XAML:
<TextBox x:Name="txtSearch" Text="{Binding Path=Filter,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
<ListView x:Name="Users" ItemsSource="{Binding Path=Items, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="SValue" SelectedValue="{Binding SelItem.SValue}" SelectedItem="{Binding SelItem}" IsSynchronizedWithCurrentItem="True" SelectedIndex="0">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=usertable_id}" Header="ID" Width="30"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=username}" Header="Username" Width="73"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=name}" Header="Full Name" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=filter}" Header="Jira Filter ID" Width="73"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=last_login}" Header="Last Loging" Width="100"/>
</GridView>
</ListView.View>
</ListView>
我的ViewModel:
// Get Data from Database.
DataTable dt = new DataTable();
baseConfig = XMLUtils.OpenXMLFile<BaseInterfaceConfig>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigParameterNames.Config));
Configuration config = new Configuration(baseConfig);
Database db = new Database(config.GetConnectionString(eDatabaseType.Customer));
var userData = db.GetObjectList<UserTableDTO>("Select usertable_id, username, name, company, email, filter, language, GetStatusMail, assigned_project_key, last_login from dbo.UserTable");
// Show DataTable "UserTable" in Listview.
view.Users.ItemsSource = userData;
// Filter
CvsStaff = new CollectionViewSource();
CvsStaff.Source = userData;
CvsStaff.Filter += ApplyFilter;
userData填充了Datatable中的数据。