ListView Update Extremely Slow When Grouping Is Used - wpf

From my understanding, the default ItemsPanel for ListView is VirtualizingStackPanel. When I create a GroupStyle for my list view, the refresh rate is terrible. Based on comments in this post
WPF ListView Very Slow Performance - Why? (ElementHost, or Other Reason?)
GroupStyle overrides the default VirtualStackPanel with StackPanel. I have explicitly declared a VirutalzingStackPanel as my ListView's ItemsPanel, but performance is still bad. Why is grouping so slow? More than likely there is something going on with grouping I don't understand.

As the author of the post below mentions
In a normal WPF ItemsControl that virtualizes, such as ListBox or ListView, virtualization turns off when you turn grouping on. This
sample shows how to achieve the same visual look of grouping and much
of the same API while still having virtualization.
Have a look at this solution developed in the sample project. However, not an easy or straight forward method at all.
Grouping and Virtualization
Remember that this method is suggested for .NET 4.0 and earlier. I believe there are new methods introduced in the .NET 4.5 which deal with this situation such as VirtualizingPanel.IsVirtualizingWhenGrouping property. However I haven't tested this since I don't have an access to .NET 4.5 atm.
VirtualizingPanel.IsVirtualizingWhenGrouping Attached Property
Gets or sets a value that indicates whether this VirtualizingPanel
virtualizes the items in its collection when it displays groups.

Related

Caching of UserControl objects

I have a WPF application where I show and hide lots of UserControl objects. The XAML code looks something like this:
<ItemsControl ItemsSource="{Binding Path=MyListOfStuff}" >
<Controls:MyControl Stuff="{Binding}"/>
</ItemsControl>
Creating those objects takes a lot of time. Profiling shows that 'InitializeComponent' takes a significant amount of time for the MyControl objects. I want to pre create these objects to reduce that time. How can I do that? I still need the xaml code and don't want to replace all of it with just code.
It's not possible to use virtualization because the items in the list are sometimes bigger than the view, so CanContentScroll must be False.
There are two aspects to solve your problem. even you can use both of them..
UI Virtualization
Data Virtualization
You should have a look at
http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/10/01/ui-virtualization-vs-data-virtualization-part-2.aspx
also if you are using .net 4.0 you can use Lazy class to support Data Virtualization easily otherwise you will have to create some classes to support that.
Regards.
It is possible to do UI caching in WPF, but I'm quite sure it is not what you are looking for.
Bitmap caching is useful when one visual is painted more than once, so it is rendered only once and for subsequent renderings only copied from the cache.
You will have to have a look at virtualization (see Shoaib's answer).
Article about bitmap caching.

Field Selection in WPF Designer - No Dropdown?

Coming from a WinForms background, I'm a little surprised to see that most (if not all) of the field-related properties for things like ItemsControls in WPF lack any sort of dropdown list for selecting fields.
For example, when using a ComboBox, if I bind the ItemsSource to a strongly-typed collection on my ViewModel in the designer, the DisplayMemberPath and ValueMemberPath properties require that I type in the names of the appropriate fields manually. My previous WinForms experience is that when binding to a strongly-typed list (in particular, a source that implements ITypedList), I would be given a dropdown of available fields so that there's no chance of fat-fingering the field name.
Am I doing something wrong here, or is this just not something that's been baked into WPF yet?
Edit
I know that this functionality was provided by the ITypedList interface in WinForms, but my understanding was that the System.ComponentModel approach to binding (PropertyDescriptors, ITypedList, IBindingList, and IListSource) were not used in WPF. Things like data grids seem to have no problems obtaining a list of fields to create columns, so I'm just curious if (and/or why) these properties that are intended to represent property names do not provide the same level of functionality.
In WPF properties like DisplayMemberPath and ValueMemberPath aren't just properties - an example might be:
<ComboBox
DisplayMemberPath="Addresses[0].Line1"
ValueMemberPath="Address[0].Id"
SelectedValue="{Binding Path=FavoriteAddressId}"
...
/>
If the designer properties only let you select from a list of properties, you'd be missing out on some pretty useful features. But you are right that providing a list in addition to being able to type it in would be useful.
There's always been a power struggle between WPF's binding system, which is quite dynamic, and the team's vision for tooling which requires a certain amount of rigidity. This is one of those cases that probably fell in the gap.
Edit: PropertyDescriptors, IBindingList and some other components of Windows Forms binding are used in WPF too - for example, my MicroModels library relies on PropertyDescriptors to work, and is built for WPF. Silverlight however doesn't support many of these.
I think this is a bug in the WPF toolkit. Check Stack Overflow question ValueMemberPath Binding in AutoCompleteBox WPF only returns top result in last name search?.
I think it has the answer to the problem.
When setting the DataContext in code it is extremely difficult for the designer to determine the type that is being bound to.
When assigning the DataContext in XAML it is much easier and although there is no drop-down in the XAML editor, when you click the little square behind the property name in the properties box you can select the properties.
In addition you can even use a design-time datacontext to add design-time types and data (beta2 related post but still valid)
My guess it is a missing feature of the XAML-editor.

WPF Combobox with auto-complete/auto-filter?

I am eager to find some solid (free, Open Source, or tutorial/example) code to make a WPF Combobox do autocomlete/autofilter as the user types. But everything I've tried so far has had some sort of problem...
A Reusable WPF Autocomplete TextBox came close, but I can't get it to work with more than one filter (more info here).
WPF autocomplete textbox/combobox doesn't work for me because it inherits from UserControl, and thus doesn't support the DataTemplates I need (for showing/selecting the value of one property for an object with multiple properties).
Automatically Filtering a ComboBox in WPF didn't work because it doesn't seem to ever find the EditableTextBox portion of the inherited ComboBox code (via (TextBox)base.GetTemplateChild("PART_EditableTextBox") which seems to always returns null).
Building a Filtered ComboBox for WPF just gets stuck in a refresh loop then overflows the stack after I type just a few letters.
Other things I've considered:
I know that Windows Forms' Combobox control has AutoCompleteMode and I could embed it in WPF, but I can't imagine it would play very well with my WPF data bindings.
Perhaps it is too complex and I need to simplify, maybe by building one-dimensional (single-property) ObservableCollections for the ComboBoxen... However, the challenge of applying multiple filters (one set by another control's value, and one from what the user is typing) to multiple controls using different views of the same DataSet would require a ridiculous amount of processing power to destroy and rebuild the list every time the user types a character!
So... I'm at wit's end. Any suggestions?
If your Combobox has some data source attached to it ,
just make
1-IsTextSearchEnabled = true.
2-IsEditable = true.
you are good to go
Try this one:
http://blogs.windowsclient.net/dragonz/archive/2010/02/23/autocomplete-textbox-control-for-wpf.aspx

Paging a Listbox control in WPF

I have a WPF ListBox with it's ItemSource property bound to an ObservableCollection. Each ListBox Item has many controls that could take some time to load up.
I would like to only display/load 5 ListBox items at a time, with some paging support or a "Next" button or something similar.
Currently I plan to do this manually and just keep two different collections. One would be the master collection with all the objects, and other would be the ListBox's collection where i would just remove 5, and put in a new 5 objects. I was just curious if there is something built in that would make my job a bit easier in this situation, i'm very new to WPF and all the binding techniques, and I have a habit of doing everything the old fashion and manual way, but I'd like to start using some of the newer 'quicker' techniques.
Thanks
just look into Bag of Tricks by Kevin
https://github.com/thinkpixellab/bot
you can see the page list viewer.... in the examples...

Silverlight ItemsControl wih ColumnHeader

How can I add column headers to a Silerlight ItemsControl? I need a fast way to display a List of items that contains also some header info.
This may seem like a simplistic question but why not use the DataGrid in readonly mode?
The downside with data grid is it doesn't use a virtualised ItemsControl so performance may suffer if you are trying to list hundreds of items with many columns.
There's nothing built into the ItemsControl itself, but there's nothing to stop you from making a custom control that has that kind of functionality. It's a little work up front for the ability to reuse it later if it's a piece of UI you need frequently.
Adding too much functionality to it might be overkill though; if you need column sorting or automatic column/header generation, you may find that a DataGrid (as Anthony pointed out already) would be a faster way of getting a lot of functionality for free.

Resources