【发布时间】:2016-10-02 06:31:00
【问题描述】:
我问了一个关于Using GotFocus and TextChanged simultaneously - Windows Phone 的问题。在上一个问题中,AutoSuggestBox 中的文本在选择建议时被清除。所以我使用了bool 类型变量来检查是否选择了建议。
现在选择任何建议时,AutoSuggestBox 应该会停止显示建议,因为我已经选择了我想要选择的内容。所以我也使用了相同的变量TextChanged 方法。
.xaml 的代码类似于:
<AutoSuggestBox
x:Name="auto_text_from"
HorizontalAlignment="Left"
VerticalAlignment="Center"
PlaceholderText="Enter Source"
Height="auto"
Width="280"
GotFocus="auto_text_from_GotFocus"
TextChanged="AutoSuggestBox_TextChanged"/>
对于.xaml.cs 是
private void OnSuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
_isSelectingSuggestion = true;
}
private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if(!_isSelectingSuggestion)
{
List<string> myList = new List<string>();
foreach (string myString in stopsList)
{
if (sender.Text.Length > 1)
{
if (myString.ToLower().Contains(sender.Text.ToLower()))
{
myList.Add(myString);
}
}
}
sender.ItemsSource = myList;
}
}
但是这样做并没有完成任务。基本上我想要的是,如果我从列表中选择任何建议,然后 AutoSuggestBox 应该停止显示建议。
谁能帮帮我。
在此先感谢 :)
【问题讨论】:
标签: c# xaml event-handling windows-phone autosuggest