这是我绑定自动填充文本框的方式: -
<sdk:AutoCompleteBox Grid.Column="1" Grid.Row="2" Height="28" HorizontalAlignment="Left" Margin="5,5,0,0" Name="autoCompleteBox" ItemsSource="{Binding List,Mode=TwoWay}" ValueMemberPath="Details" FilterMode="Contains" VerticalAlignment="Top" Width="400" SelectedItem="{Binding Path= SelectedFromList,Mode=TwoWay
<sdk:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Details}" VerticalAlignment="Center" Margin="10 0 0 0" />
</StackPanel>
</DataTemplate>
</sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>
问题是我无法从Autocompletetext框中清除以前搜索过的数据,每次搜索时都显示我之前搜索过的所有记录。
有人可以建议如何清除以前的记录吗?
答案 0 :(得分:1)
我不知道如何在ViewModel中执行此操作,但在事件“填充”中的代码中 清除selectedItem和Itemsource并再次绑定它,它将起作用,
var items = this.autoCompleteBoxSingle.ItemsSource;
this.autoCompleteBoxSingle.ItemsSource = null;
this.autoCompleteBoxSingle.SelectedItem = null;
this.autoCompleteBoxSingle.ItemsSource = items;