在WP7中禁用自动完成框中的自动选择?

时间:2011-09-22 09:12:35

标签: windows-phone-7 windows-phone-7.1 autocompletebox

有没有办法在WP7的AutoCompleteBox中禁用AutoSelect?现在发生的事情是,每当我写一些内容并且它在搜索建议中列出时,逻辑就会运行。这不是我想要的,因为用户只想在点击建议,回车键或搜索按钮时进行实际搜索。所以,我的问题是:如何禁用它?

现在如何完成:

在xaml文件中,显示AutoCompleteBox并将其绑定到key up和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>

在xaml.cs中,我听取keyup事件并向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();
        }
    }

在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;
        }
    }

问题似乎是当我点击下拉菜单时,也会在我输入下拉列表中列出的内容时引发SelectionChanged事件。希望有人可以提供帮助:)

0 个答案:

没有答案