Is there any way to disable the AutoSelect in the AutoCompleteBox in WP7? What happens now is that each time when I write something and it is listed in the search suggestions, the logic runs. This is not what I want, because the user would only like to do the actual search when clicking on a suggestion, the enter key or the search button. So, my question is: How is it possible to disable this?
How it is done now:
In the xaml file, showing the AutoCompleteBox and binds it to key up and selectionchanged:
<toolkit:AutoCompleteBox x:Name="AutoCompleteBox" FilterMode="None" ItemsSource="{Binding SearchSuggestion}" KeyUp="AutoCompleteBoxKeyUp" MinimumPrefixLength="3">
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding TextBoxKeyUpCommand, Mode=OneWay}" CommandParameter="{Binding Text, ElementName=AutoCompleteBox}"/>
</i:EventTrigger>
<i:EventTrigger EventName="SelectionChanged">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="TextBoxSelectionChanged" Command="{Binding TextBoxSelectionChangedCommand, Mode=OneWay}" CommandParameter="{Binding Text, ElementName=AutoCompleteBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</toolkit:AutoCompleteBox>
In xaml.cs I listen to the keyup event and send a message to the viewmodel:
private void AutoCompleteBoxKeyUp(object sender, KeyEventArgs e开发者_运维知识库)
{
if (e.Key == Key.Enter)
{
Messenger.Default.Send(new ViewModelMessage { Action = ViewModelMessage.ACTION_EXECUTE, Text = AutoCompleteBox.Text });
Pivot.Focus();
}
}
In the ViewModel:
private void TextBoxKeyUp(string string)
{
_string = string;
}
private void TextBoxSelectionChanged(string string)
{
_string = string;
}
private void ReceiveMessage(ViewModelMessage message)
{
switch (message.Action)
{
case ViewModelMessage.ACTION_EXECUTE:
_string = message.Text;
break;
}
}
The problem seems to be that the SelectionChanged event is raised when I click on the drop down, but also when i type in something that is listed in the drop down. Hope someone can help :)
精彩评论