WPF Paged CollectionViewSource - wpf

I have a WPF ListBox that I would like to add pagination to as it starts getting slow with a bunch of items. My problem is that I use the Grouping, Sorting, and Filtering. That means if I were to limit the data with the LINQ Skip() and Take() methods or using something like a paginated ObservableCollection the grouping and sorting would be wrong because it would only be applied to the first page of data. Filtering would be even worse because it would just filter the data displayed in the current display which would mean you would have to be on the page that it would show up on to be able to search for it.
I'm not too keen on the idea of rewriting all of that logic. I see Silverlight 3 is getting a PagedCollectionView (but as far as I can tell WPF in .NET 4 is not getting it). Has anyone implemented something like this before or have any ideas on how I should solve this?

Check out a simple Paginated ObservableCollection I have implemented - works for Silverlight as well as WPF
http://jobijoy.blogspot.com/2008/12/paginated-observablecollection.html

Related

ListView Update Extremely Slow When Grouping Is Used

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.

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

Optimizing the infragistics wpf datagrid

I should start out with the disclaimer that I don't have a lot of info into this problem, but I wanted to put a feeler out to see if anyone else had this problem. I started a new job and some folks here are using Infragistics WPF datagrid. The grid was selected because of the visual flexibility, but apparently when there are large amounts of rows in the grid, things begin to perform very poorly. This is possibly due to implementation (not sure, haven't gotten into the code yet) and shouldn't be taken as a negative on the control.
Has anyone else encountered and have any advice I could pass onto the developers? Thanks in advance.
Edit*: I think introducing paging might not be an option. The grid is being used in such a capacity that it is displaying data streamed into it. So the use case is that the end user is monitoring 50-100 rows that are updating with new values intra-second (aka - think running stock tickers instead of flipping through a result set)
I'm having problems with XamDataGrid as well. Although I don't have the right version to attempt this, you might try changing to the high-performance hoverless style, and suppressing events, as described here:
http://blogs.infragistics.com/forums/p/48307/264160.aspx
The rest of the suggestions are a lot more specific and handle particular schemas and use-cases.
Here's a bit more of an overview of Infragistics optimizations:
http://help.infragistics.com/NetAdvantage/WPF/2010.3/CLR4.0/?page=xamData_Performance_Optimizations_Overview.html
I am using the Xceed DataGrid, but I recently discovered our DataGrid was binding to a View (DataGridCollectionView) and not to a datasource (DataView/DataTable).
This meant we replaced the entire view for each refresh.
By binding to a DataTable, my code now refreshes the DataGrid instantly with a few thousand rows where it use to take 1-2 seconds.
As most grids are similar. please verify how your code is binding to the data that goes into your DataGrid.
I posted some code here in case that helps.
The approach is take is to enable virtualisation - this ensure that only the information on the screen is involved in a repaint. See no problem with 100 rows being continuously updated.

Sorting Data using Silver light Data Grid control

I have a grid control in silverlight.I set up pagination for this control.Data is populated from db.I am trying to a sorting on all column headers.However sorting gets applied to specific page and does not apply to entire result set.How can this issue be fixed? Any suggesstions would be of great help.
Regards,
Pri
You can provide explicit IComparer implementations for the columns, as well as event handlers, to handle both questions.
Handle the click event on the header to resort your data however you like.
http://www.longhorncorner.com/UploadFile/nipuntomar/SortingDataSilverlightDataGrid09152008025951AM/SortingDataSilverlightDataGrid.aspx
And leverage the ICollectionView IComparer implementation to do the sorting of the HyperLinks
http://msdn.microsoft.com/en-us/library/system.windows.data.listcollectionview.aspx
(is the text of the hyperlinks all the same, e.g. ClickMe ?)
Also - since Silverlight is running on the client, has all the data been brought to it (or just that page's data, and paging is bringing data to the client)? eg what data source are you using? RIA Services and DomainDataSource? Or your own service calls?)
You might want to use PagedCollectionView. PagedCollectionView gives you lot of functionality out of the box without writing much code.You can use it to sort the data,filter the data,group the data.
Get your data from server in the way you prefer and create a PagedCollectionView with the object collection retrieved from the server and bind the datagrid with PagedCollectionView.
You can sort the data by adding SortDescriptions.
It is explained with examples at MSDN. Especially look for sort section.
Hope this helps.

C# 4.0 .net 4 and WPF UI update

I'm trying to build an app to work with twitter like site , and the problem I'm trying to solve is -
How am i going to update the UI with a background worker and only add show the latest posts(tweets if you will )
on top of the wrap panel without removing the ones that already exist?
in my previous attempt i have done this by storing the tweets/posts in a local SQlite database and then retrieving the last 10 posts which causes the UI to freeze for a bit and reload all the posts.
Any ideas ?
Since you're using WPF, this is fairly easy.
Just store your "posts" in an ObservableCollection<T>. You can then just Insert the new item at the front of the list. If you've bound this to an ItemsCollection control, WPF will handle redrawing everything correctly for you.
Unless you have a LOT of elements, this will work quite well, and be fairly fast. I'd try it first (since it's really easy to implement), and only try to get more "clever" if you find that it has performance problems. I doubt you'll have issues, though, provided you use the proper collections, since WPF's data binding to ObservableCollection is quite fast.
Use databinding. The UI elements are databound to fields of a record in a collection. The panel of multiple rows should be an ItemCollection of some sort - Listbox, most likely - so that it will replicate the item data template for each row in the underlying data collection.
After that, the UI will track with any changes made to the underlying collection, if the collection implements INotifyCollectionChanged. If you use an in-memory collection, you can just add new data to the top of the collection (Insert at index 0) and that will push all the old items down in the UI display. If you use a file or server based data source, you can fetch the data in a background thread and post updates to the in-memory collection on the foreground thread. Just don't update the databound collection from the background thread.

Resources