Paging a Listbox control in WPF - 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...

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: TemplateSelectors for different GridViews

Currently I have a UserControl that displays collections of data in the same layout. So one control could be instanced with a collection of ObjectA and another of ObjectB. I then use TemplateSelectors to choose the right DataTemplates.
Later on we thought we'd set the List as a GridView to show more information in the list itself. However each type of object has different properties and the columns may have different names and not the same quantity. I realized then that the columns and such where not set in the ItemTemplate but at the GridView itself and ListView of course has no templateSelector for itself.
I wasn't sure how to do it but several ways came into mind.
1) There is some kind of TemplateSelector property I'm not aware off.
2) I CAN set it somehow at the ItemTemplateSelector only don't know how.
3) I could do the GridView dynamically (could be difficult and wan't to avoid).
Any good way to do this, tutorials or similiar I could use?
EDIT:
As I have learned a little bit more about ListView and it's view property I'm pretty sure I could define the gridview in a staticResource. Still I would love a ViewSelector or something similar. I guess this was of course not intended as the the item could be dynamic while the Collection isn't.
But I'm thinking about cases where there could exist more types of view then gridview ( iconview or something else) and the user could switch between them it would have to be implemented in some way.
The solution I see know is using a trigger and basing it on the first item in the collection but I'm not liking that too much.
Have you looked at the AutoGeneratingColumns property of the Grid?
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.autogeneratingcolumn(v=vs.95).aspx

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

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.

Can you turn off selection syncing in WPF's CollectionViewSource?

I have several CollectionViewSource instances all used on the same ObservableCollection. I also have several controls that need to show filtered versions of the collection (hence the CollectionViewSources). The problem I'm having is that CollectionViewSource forces them to all have the same item selected. Is there some way to turn this off?
Thanks,
Jason Lewis
If you use the method (im not sure about this but CollectionViewSource in xaml probably does)
CollectionViewSource.GetDefaultView(this.ItemsSource);
multiple times it will only return the same ICollectionView (if we are talking about the same collection bound multiple times), this means if you apply a filter to one it apllies to all, also as the collection view tracks the current item the current item will be syncronised between the different views.
You can work around this by creating a CollectionView for each filter/selection you want to have by using
new CollectionView(this.ItemsSource as IList);
there are a few types that implement ICollectionView, CollectionView and ListCollectionView do. in the above code i did not get the default view i created a new one, so its filering/sorting is unique.
When you use items source wpf creates a collection view to wrap the collection, this collection view is the one that is returned in the GetDefaultView call, useful for every day situations but not the edge cases.
here is a blog post from bea that explains it a bit better

Resources