所以基本上我有ListView
这样:
<ListView x:Name="Contacts" ItemsSource="{Binding Contacts}"
SelectionChanged="Contacts_SelectionChanged" SelectionMode="Single"
SelectedItem="{Binding Contact, Mode=TwoWay}" />
以这种方式应用过滤器:
CollectionViewSource.GetDefaultView(Contacts.ItemsSource).Filter = GeneralUtility.FilterMethod;
现在,当用户选择联系人时,应用程序会使用联系信息填充所有控件。当用户使用过滤器搜索联系人时,SelectedItem
将在搜索到的项目时丢失。
Contacts
绑定是一个列表:
public List<Contact> Contacts { get; set; }
,SelectedItem
是所选的联系人:
private Contact _contact;
//Current contact selected
public Model Contact
{
get { return _contact; }
set
{
_contact = value;
OnPropertyChanged();
}
}
一个练习例子:
> User select the item on the contacts list
> User search a contact on the list
> The filter cause the selecteditem to change <-- problem here
如您所见,我需要阻止最后一步自动更改选定项目(只有用户可以更改所选联系人)。
保留用户的SelectedItem的任何想法或解决方案?