如何在Windows Phone 8中为长列表选择器创建可搜索的文本框

时间:2014-04-10 11:03:41

标签: windows windows-phone-8 windows-phone

请帮助重现...到可搜索的长列表选择器。

如何在Windows Phone 8平台中为长列表选择器创建可搜索文本框。

感谢任何帮助

提前感谢。

1 个答案:

答案 0 :(得分:0)

//查看 因此,创建TextBox和按钮=>

<StackPanel Orientation="Horizontal">
                <TextBox Width="200" Text="{Binding Text,Mode=TwoWay}"></TextBox>
                <Button Command="{Binding Search}"></Button>
</StackPanel>

//视图模型

  private List<AlphaKeyGroup<CountryInfo>> _dataSource;

  public List<AlphaKeyGroup<CountryInfo>> DataSource
  {
    get { return _dataSource; }
    set
    {
       _dataSource= value;
       RaisePropertyChanged(() => DataSource);
    }
   }

  private string _searchText;

  public string SearchText
  {
     get { return _searchText; }
     set {
           _searchText= value;
           RaisePropertyChanged(() => SearchText);
          }
   }
    public RelayCommand Search {get;set;}

//构造

Search = new RelayCommand(setSearchList);

//了Methode

    private void setSearchList(){

      if(string.isNullOrEmpty(SearchText)){
        DataSource = AlphaKeyGroup<CountryInfo>.CreateGroups(CountryInfoList,    System.Threading.Thread.CurrentThread.CurrentUICulture, (CountryInfo s) => { return s.Name; }, true);
      }else{
        var listCopy= CountryInfoList.where(item=> item.Name == SearchText).ToList();
         DataSource = AlphaKeyGroup<CountryInfo>.CreateGroups(listCopy, System.Threading.Thread.CurrentThread.CurrentUICulture, (CountryInfo s) => { return s.Name; }, true); }
    }

您的itemSource是DataSource属性。