Pages

Thursday, 28 July 2011

Geek Definition/Evolution - Whose of them are you?

The Evolution of the Geek
Flowtown - Social Media Marketing Application

Tuesday, 26 July 2011

Filtering in MVVM architecture - Silverlight & WPF

Before you start implementing functionality for filtering data in MVVM architecture you have to find out which technologies you are going to use. There are two different ways how you can implement filtering in WPF but only one solution can be ported to Silverlight. The reason behind it is that Silverlight version of CollectionViewSource class does not support GetDefaultView method. The following example shows how you can filter data in MVVM architecture by changing the content of FilteringMethod predicate.


   1:  class MainWindowPresentationModel : INotifyPropertyChanged
   2:      {
   3:          ObservableCollection<string> _observableCollection = new ObservableCollection<string>() { "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "eeeeeeee", "fffffffffffffff", "gggggggggggggggggg" };
   4:          private int _threshold = 100;
   5:          private ICollectionView _Items;
   6:          private CollectionViewSource _CollectionViewSourceItems;
   7:          public event PropertyChangedEventHandler PropertyChanged;
   8:   
   9:          public MainWindowPresentationModel(Window window)
  10:          {
  11:              FilterCommand = new RoutedCommand();
  12:              CommandBinding customCommandBinding = new CommandBinding(FilterCommand, HandleFilterCommand);
  13:              window.CommandBindings.Add(customCommandBinding);
  14:   
  15:              window.DataContext = this;
  16:              window.Show();
  17:   
  18:              Items = CollectionViewSource.GetDefaultView(_observableCollection);
  19:              Items.Filter = FilteringMethod;
  20:              Items.Refresh();
  21:   
  22:              CollectionViewSourceItems = new CollectionViewSource();
  23:              CollectionViewSourceItems.Source = _observableCollection;
  24:              CollectionViewSourceItems.View.Filter = FilteringMethod;
  25:              CollectionViewSourceItems.View.Refresh();
  26:          }
  27:   
  28:          public ICommand FilterCommand
  29:          {
  30:              get;
  31:              set;
  32:          }
  33: