Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 文本更改事件的自动完成框选择不正确_Silverlight_Xaml_Silverlight 5.0 - Fatal编程技术网

Silverlight 文本更改事件的自动完成框选择不正确

Silverlight 文本更改事件的自动完成框选择不正确,silverlight,xaml,silverlight-5.0,Silverlight,Xaml,Silverlight 5.0,嗨,我正在使用一个像这样的自动完成框 <!-- XAML Code --> <sdk:AutoCompleteBox Grid.Row="2" FilterMode="None" ItemsSource="{Binding Customers}" SelectedItem="{Binding Path=SelectedCustomer, Mode=TwoWay}" Text="{Binding Custom

嗨,我正在使用一个像这样的自动完成框

<!-- 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部分:

//视图模型中的搜索方法
公开无效搜索()
{
var customerOperation=_context.Load(_context.GetCustomerByNameQuery(CustomerSearchString));
customerOperation.Completed+=(s,e)=>客户=新列表(customerOperation.Entities);
}
在我的应用程序中快速搜索客户,以获得快速而简单的搜索方法。我让它在下拉列表中正确显示所有内容,当我用鼠标选择时,它可以完美地工作

但当我按下ArrowDown键时,您会看到文本在一瞬间出现,但随后它会恢复并将光标放回文本框,而不是选择第一个向下的条目。我尝试使用TextInput事件,但该事件无法启动

我怎样才能避免这种行为

解决方案:

<!-- 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}}"/>
问题是,当用户选择一个条目时,TextChanged事件被触发,从而在文本被重置时创建了某种类似于竞争条件的行为。解决方案是使用KeyUp事件(不要使用KeyDown,因为文本属性还不会更新)。当用户选择某个内容解决问题时,不会触发此事件

最终代码(视图模型不变):

<!-- 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}}"/>


谢谢大家

在代码中添加如下处理程序:

KeyEventHandler eventHandler = MyAutoCompleteBox_KeyDown;
MyAutoCompleteBox.AddHandler(KeyDownEvent, eventHandler, true);

我不明白你为什么要使用TextChanged事件。。。?那是干什么用的?如果你把它拿出来,它能用吗?我在我的项目中使用自动完成框,我不需要搜索方法。。。我所做的只是向autocompletebox提供一个对象列表,当用户键入时,它会搜索该列表。我可以通过鼠标或上/下箭头进行选择。我能想到的唯一一件事是,每次你尝试使用向上/向下箭头时,文本都会发生变化,启动搜索功能并关闭选择选项下拉菜单…

我使用它进行搜索,因为整个集合无法被RIA服务消化,而且它也会有太多的数据(超过10000个数据集)。嘿!谢谢,这几乎就是解决方案,但是:a)我使用XAML标记是因为我不需要代码,而我使用KeyUp,因为在KeyDown上,文本属性还没有更新。感谢并祝贺你得了50分:D