简体   繁体   English

如何清除AutoSuggestBox项目

[英]How can I clear AutoSuggestBox items

I have an AutoSuggestBox and its ItemSource is bounded from my VM. 我有一个AutoSuggestBox,其ItemSource受我的VM限制。

<AutoSuggestBox x:Name="MyBox" Grid.Row="1" GotFocus="MyBox_GotFocus"
                            QueryIcon="Find" PlaceholderText="Search"
                            QuerySubmitted="MyBox_QuerySubmitted"
                            TextMemberPath="Description"
                            Header="Search"
                            ItemsSource="{Binding SearchMatches}" 
                            Style="{StaticResource SearchAutoSuggestBoxStyle}" 
                            ItemTemplate="{StaticResource SearchItemTemplate}"/>

So lets say it is like this: 所以可以这样说:

在此处输入图片说明

How can i delete/clear its items/Suggestions on my Void Method? 我如何在我的作废法中删除/清除其项目/建议?

MyBox.Items.Clear() // this shows Catastrophic failure error

Thanks 谢谢

You generally don't want to interact with Items directly when you are using data binding. 使用数据绑定时,通常您不希望直接与Items交互。 Try Clear on your underlying collection property instead. 请尝试在基础集合属性上Clear

SearchMatches.Clear();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM