2017-08-08 90 views
1

我有一个AutoSuggestBox,它的ItemSource与我的虚拟机有关。我该如何清除AutoSuggestBox项目

<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}"/> 

因此,可以说是这样的:

enter image description here

如何删除/清除其项/建议我void方法?

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

感谢

+0

'SearchMatches.Clear()'。 –

+0

@JustinXL大声笑今天太多的代码,我对一个简单的问题xD感到困惑,你能否请把这添加为答案,所以我可以将它标记为答案谢谢 – NicoTing

+0

是的,这发生在我们所有人身上。 :) –

回答

0

你一般不愿意直接当您使用数据绑定与Items互动。改为在底层集合属性上尝试Clear

SearchMatches.Clear(); 
相关问题