![]() ![]() If on the other hand you’re dealing with performance issue too, you might try my solution □Īs you might already know, I’m a big fan of the Model-View-ViewModel pattern. If you have any idea, I’d be glad to know. I don’t know what could slow down the performance of the filtering using the ICollectionView interface. ![]() In the View, I setup a simple style for my ListViewItem that databound the IsVisible property to the visibility property (using the BooleanToVisiblity converter included in the framework). This IsVisible property is toggled when the search is performed: I iterate over the ObservableCollection of items, and change the IsVisible property regarding whether the item match the search text or not. / Gets or sets a value indicating whether this item is visible in the collection I added a IsVisible property to the ViewModel objects that are in the ListView. And thanks to the MVVM methodology, I found one quickly ! ![]() Because the filtering was slow, I found another solution which is much faster. ![]() Each item in the ListView is rendered using a simple DataTemplate made of one Image and several TextBlock. There is around 200 items in the ListView, and because I wanted to leverage the ICollectionView interface, I used the Filter property to enable search functionality.Unfortunately, the performance was pretty poor and until now I didn’t find out what goes wrong. In my project at work, I have a “Library” which lets the user choose an item in it, and drop it somewhere else in the application. The ICollectionView also enables the ViewModel to perfom Sorting, Grouping and Filtering very easily (basically by using the Sort, Group and Filter properties). This interface is very important in the MVVM methodology because it enables the possibility to track the selection of the user in ItemsControl based-controls (ListView, ListBox, ComboBox, TabControl…). In my “Why should I use MVVM pattern” post, I gave a link to a post explaining the ICollectionView interface. You can download the source code of this sample (VS2010 RC solution). I had to create an attached property because its value is true when the ListBoxItem is selected AND the parent ListBox has IsSelectionActive set to true. This enables to databing an IsSelected property of the ViewModel class behind the control with the IsSelected of the ListBoxItem. I added an IsReallySelected attached property to the ListBoxItem which are generated.The CustomControl has a SelectedItem property and a SelectionChanged event (like Selector-derived class).The CustomControl automatically databound ListBoxes together: each ListBox’s ItemsSource property is databound to the SelectedItem’s children property of the previous ListBox in the visual tree.This property indicates the number of ListBox that should be generated. The CustomControl has a Depth property of type int.This ItemsControl has its ItemTemplate property set to a DataTemplate containing a ListBox. In the template of this CustomControl is an ItemsControl.I create a new CustomControl which inherits Control (I couldn’t use neither Selector or TreeView because I wouldn’t have been able to manage the SelectedItem property from the derived class).The solution I finally choose involves creating multiple ListBox and wire them together using DataBinding: I though at the beginning that playing with the templates of the TreeView and TreeViewItem would do the trick but it didn’t. I asked a question on StackOverflow about this control because I didn’t find any easy way to do it. To understand what I mean, I wanted to change the layout of this: Last week at work I was requested to create a new control which should have the behavior of the WPF treeview with a template involving multiple ListBox. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |