In App Search in wp7 app

I've a listbox which has many items. I'm trying to create a search bar so that a user can type in what he is looking for and my listbox displays only those items relevant to what the user has typed in textbox. I'm new to wp7

Answers


First you should use MVVM for proper Layout updating. Then use additional property and bind it to TextBox. When property was updated - rise another property changed event to update ListBox (FirePropertyChanged("FooList"); in snippet).

public class Foo
{
    public string Name { get; set; }
}

in ViewModel:

public string SearchCriteria
{
     get
     {
         return searchCriteria;
     }
     set
     {   
         serchCriteria = value;
         RaisePropertyChanged("SearchCriteria");
         RaisePropertyChanged("FooList");
     }
}
private List<Foo> fooList;

public List<Foo> FooList
{
    get 
    {
       return fooList.Where(x => x.Name.Contains(searchCriteria)); 
    }
}

in Xaml:

<TextBox x:Name="searchText" Text={Binding SearchCriteria, Mode=TwoWay} />
<ListBox x:Name="elementsList" ItemsSource={Binding FooList, Mode=TwoWay}>
  <ListBox.ItemTemplate>
   ...
  </ListBox.ItemTemplate>
</ListBox>


Some help links for better understanding MVVM pattern:


Need Your Help

How to access session custom action data (properties) during install and uninstall in Wix?

session wix install uninstall

Can you please tell me what is wrong with the following code? I am able to access the custom action data during install and I add their values to session custom action collection. However, during

How to disable home button like 'cover' app?

android lockscreen android-homebutton

As far as I know, there is no way to disable 'Home button' in android system.