嗨我使用的是AutoCompleteBox这样AutoCompleteBox与TextChanged事件没有选择正确
<!-- XAML Code -->
<sdk:AutoCompleteBox Grid.Row="2"
FilterMode="None"
ItemsSource="{Binding Customers}"
SelectedItem="{Binding Path=SelectedCustomer, Mode=TwoWay}"
Text="{Binding CustomerSearchString, Mode=TwoWay}"
ValueMemberBinding="{Binding Path=FullName}"
ValueMemberPath="FullName"
TextChanged="{ext:Invoke MethodName=Search, Source={Binding}}"/>
C#部分:
// Search Method in the viewmodel
public void Search()
{
var customerOperation = _context.Load(_context.GetCustomerByNameQuery(CustomerSearchString));
customerOperation.Completed += (s, e) => Customers = new List<Customer>(customerOperation.Entities);
}
在我的应用程序快速搜索客户的快速和简单的搜索方法。我可以在下拉菜单中正确显示所有内容,当我用鼠标选择它时,它可以完美地工作。
但是,当我按下ArrowDown时,您会看到文本出现一瞬间,但之后它会恢复并将光标放回到文本框中,而不是选择第一个条目。我尝试过使用TextInput事件,但那个不会触发。
我怎样才能避免这种情况?
SOLUTION:
的问题是,当用户选择一个条目,创建某种类似行为的竞争条件,其中的文本得到重置TextChanged事件被解雇了。 解决方案是使用KeyUp事件(不要使用KeyDown,因为Text属性将不会更新)。当用户选择某些东西解决问题时,不会触发此事件。
最终代码(视图模型不变):
<!-- XAML Code -->
<sdk:AutoCompleteBox Grid.Row="2"
FilterMode="None"
ItemsSource="{Binding Customers}"
SelectedItem="{Binding Path=SelectedCustomer, Mode=TwoWay}"
Text="{Binding CustomerSearchString, Mode=TwoWay}"
ValueMemberBinding="{Binding Path=FullName}"
ValueMemberPath="FullName"
KeyUp="{ext:Invoke MethodName=Search, Source={Binding}}"/>
谢谢大家!
嘿!谢谢,那几乎就是解决方案,但是:a)我使用XAML-Markup,因为我不需要代码并使用KeyUp,因为在KeyDown上Text属性尚未更新。感谢并祝贺50分:D – LueTm