Ank*_*eer 3 c# windows-phone winrt-xaml windows-phone-8.1
在选择AutoSuggestBox中的项而不是属性值时,它将绑定到该属性.
这是我的xaml.
<AutoSuggestBox x:Name="txtSearchBox" ItemsSource="{Binding}"
PlaceholderText="Search in Distributor" Style="{StaticResource AutoSuggestBoxStyle1}"
Margin="10,25,10,0" DisplayMemberPath="{Binding entityName}" TextMemberPath="{Binding entityName}"
BorderBrush="#000000" BorderThickness="2" TextChanged="txtSearchBox_TextChanged"
SuggestionChosen="txtSearchBox_SuggestionChosen">
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding entityName}"
Tag="{Binding entityId}"/>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>
Run Code Online (Sandbox Code Playgroud)
这就是守则背后
private void txtSearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
List<Master_User_Hierarchy_VM> lstUserHierarchy = new List<Master_User_Hierarchy_VM>();
txtSearchBox.ItemsSource = null;
foreach (Master_User_Hierarchy_VM obj in lstMaster_UserHierarchy_VM)
{
if (sender.Text != "")
{
if (obj.entityName.Contains(sender.Text))
{
lstUserHierarchy.Add(obj);
}
}
}
txtSearchBox.ItemsSource = lstUserHierarchy;
}
else if (args.Reason == AutoSuggestionBoxTextChangeReason.SuggestionChosen)
{
//txtSearchBox.Text = txtSearchBox.Items[0].ToString();
}
}
private void txtSearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
txtSearchBox.Text = ((Master_User_Hierarchy_VM)args.SelectedItem).entityName;
}
Run Code Online (Sandbox Code Playgroud)
这是我输入一个角色的时候
当我单击此列表中的项目时
我再次在建议框中获取所选项目.当我点击它时,我得到属性名称而不是值
使用
TextMemberPath="entityName"
Run Code Online (Sandbox Code Playgroud)
代替
TextMemberPath="{Binding entityName}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1819 次 |
| 最近记录: |