2017-08-08 47 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();