2011-11-29 46 views
0

我這是怎麼結合的自動完成文本框: -如何從自動完成文本框清除搜索歷史記錄在Silverlight

<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

看看這裏:HTTP ://stackoverflow.com/questions/5141529/sl4-autocompletebox-repeating-filter-results-issue –

回答

1

我不知道如何在落後的情況下做到這一點的視圖模型,但代碼「填充」 明確將selectedItem和的ItemSource和再次綁定它,它會工作,

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