【问题标题】:How to clear the Search History from the Autocomplete Textbox in Silverlight如何从 Silverlight 中的自动完成文本框中清除搜索历史记录
【发布时间】:2011-11-29 06:38:44
【问题描述】:

这就是我绑定自动完成文本框的方式:-

<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>

问题是我无法从自动完成文本框中清除以前搜索过的数据,每次搜索时都会显示我以前搜索过的所有记录。

谁能建议如何清除以前的记录?

【问题讨论】:

标签: silverlight mvvm


【解决方案1】:

我不知道如何在 ViewModel 中执行此操作,但在“填充”事件中的代码中 清除 selectedItem 和 Itemsource 并再次绑定它,它会工作,

    var items = this.autoCompleteBoxSingle.ItemsSource;
    this.autoCompleteBoxSingle.ItemsSource = null;
    this.autoCompleteBoxSingle.SelectedItem = null;
    this.autoCompleteBoxSingle.ItemsSource = items; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 2020-11-10
    • 2013-05-04
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多