C# 如何从Windows Phone 8.1中的AutoSuggestBox中获取所选项目
在CS文件中,SelectedItem不起作用WP8.1中SelectedItem for AutoSuggestBox的替代方案是什么 在XAML文件中:C# 如何从Windows Phone 8.1中的AutoSuggestBox中获取所选项目,c#,visual-studio-2013,C#,Visual Studio 2013,在CS文件中,SelectedItem不起作用WP8.1中SelectedItem for AutoSuggestBox的替代方案是什么 在XAML文件中: <AutoSuggestBox x:Name="tblkpersonname" Width="380" Margin="0,-7,0,0" ItemsSource="{Binding}" TextChanged="tblkpersonname_TextChanged"> <AutoSugge
<AutoSuggestBox x:Name="tblkpersonname" Width="380" Margin="0,-7,0,0" ItemsSource="{Binding}" TextChanged="tblkpersonname_TextChanged">
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"
Tag="{Binding PersonID}"/>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>
Windows Phone 8.1提供的自动建议框中没有SelectedItem,Windows 10的开发者工具中也没有SelectedItem。 AutoSuggestBox的工作原理类似于常规文本框,唯一的优点是可以有一个面板/弹出窗口,根据您传递的项目资源提供建议。 实际上,它只在ItemsSource是字符串集合时才起作用,因为DisplayMemberPath不起作用,至少对我来说是这样。 因此,检索SelectedItem的唯一方法应该是使用Text属性。 我知道它实际上不一样,但AutoSuggestBox它不是组合框。Xaml
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
<AutoSuggestBox
Text="{Binding EnteredAddress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding AddressAutoComplete}"
ItemTemplate="{StaticResource Autocomplete}"
TextMemberPath="name">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SuggestionChosen">
<core:InvokeCommandAction Command="{Binding TextSearchChangedCommand}" CommandParameter="{Binding this}">
</core:InvokeCommandAction>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
视图模型棱镜
TextSearchChangedCommand = new DelegateCommand<Object>((Object) =>
{
method(Object);
});
public void method(Object adr)
{
AutoSuggestBoxSuggestionChosenEventArgs a = (AutoSuggestBoxSuggestionChosenEventArgs)adr;
Address selected = (Address)a.SelectedItem;
}
我花了一整天才意识到:-
TextSearchChangedCommand = new DelegateCommand<Object>((Object) =>
{
method(Object);
});
public void method(Object adr)
{
AutoSuggestBoxSuggestionChosenEventArgs a = (AutoSuggestBoxSuggestionChosenEventArgs)adr;
Address selected = (Address)a.SelectedItem;
}