Apply filter to sfKanban control
works but only on the initial binding. When a command is called, the DoFilter function is called, but there is no effect on the view in the Kanban board.
Any suggestions?
example:
class CarViewModel : INotifyPropertyChanged
{
public CarViewModel ( )
{
MyCarCollection = new ObservableCollection<Car>();
PopulateCollection( );
_inventoryView = CollectionViewSource.GetDefaultView( MyCarCollection );
// the code here works
this.FilterString = "2008";
_inventoryView.Filter = YearFilter;
}
// CollectionViews
//
private ICollectionView _inventoryView;
public ICollectionView InventoryView
{
get { return _inventoryView; }
}
private string _filterstring;
public string FilterString
{
get { return _filterstring; }
set { _filterstring = value;
OnPropertyChanged("Filter");
_inventoryView.Refresh();
}
private bool YearFilter( object item )
{
Car x = item as Car;
return x.Year.Contains(filterstring);
}
public void ApplyFilter()
{
// the code here doesn't work, even though it is triggered
MessageBox.Show ("filter is being applied");
this.Filterstring = "2008";
_inventoryView = YearFilter;
}
}
Thank you for the sample Rachel, it's not very different from my approach.
However I'm trying to avoid code-behind, so my example has a button bound to an ICommand, which then executes the ApplyFilter( ) function in the viewmodel.
In your example, similar to what you have a button_click even handler to null out the ItemSource before applying the filter. I could have also implement it this
way but I'd like to use the commanding approach.
What I was hoping to achieve is that the filter would be set (on the CollectionView ) in the viewmodel, and this would then notify the Kanban control to update itself.
Perhaps I'm using Property notifications incorrectly and should be using COllection notifications, but the collection isn't really changing, only the collectionview.
See attached example.
thanks
Attachment: WpfFilteringExample_ebdc6870.zip
Thanks Rachel. Your solution works. However I found that if the filter was cleared, then your code would no longer update the Kanban control,
because the ItemSource was nulled out. The solution I found is something like shown below, a slight variation to yours
public void ExecFilter( object param ){
SfKanban myKanbanObj = param as SfKanban;
myKanbanObj.ItemSource = null;
_inventoryView.Filter += YearFilter;
OnPropertyChanged("Filter");
myKanbanObj.ItemSource = _inventoryView; // now the filter can be reapplied after clearing
}
public void ClearFilter( )
{
_inventoryView.Filter = null;
OnPropertyChange("Filter");
}
- 6 Replies
- 2 Participants
-
MD Milan Danrel
- Oct 16, 2017 03:07 PM UTC
- Oct 19, 2017 10:23 AM UTC