Adding filter textbox to header of a Listview in Gridview mode - wpf

I watched a demo video of Mole 2010 (a WPF debugger) in which there is a nice datagrid feature where the header contains a filter textbox, so you can type in a string and filter for that column. Here is the video, the feature is demonstrated at 3:00 minutes
http://www.youtube.com/watch?v=bgMg61iM9G8&feature=player_embedded#at=180
I am interested in replicating that feature, but I am not sure how to do it gracefully. My application is a WPF MVVM EF app, it's my first WPF app.
Is it possible to create a template for the header where I can also add a textbox, and a button with a cross so the contents can be cleared?
If so, how could I bind the textbox to filter its column?
Should I be hiding the actual header row and making an artificial one where I add my own header and textbox and button etc. and then bind them to filter clause properties that I add to my CollectionViewSource when a filter string is typed? I hoped to avoid this so I could retain sorting by clicking the header.
I dont really know how to start this. Are there any gurus that could suggest how this could be done? Thanks!

You might have a look at the BookLibrary sample application of the WPF Application Framework (WAF). It shows how to use a TextBox for filtering the data in a DataGrid. It uses MVVM and the Entity Framework as well.

you might want to try that : http://dotnetexplorer.blog.com/2011/04/07/wpf-itemscontrol-generic-staticreal-time-filter-custom-control-presentation/ => it filters any collections and you just have to decalre the control in XAML...

Related

WPF Datagrid with similar Outlook 2013 mail list style

I am new to WPF. I want to design a Datagrid similar to mail list in outlook 2013 having same style and features.
In outlook 2013, Datagrid template changes when its width decreases and goes to one liner type of mode when it expands.
I tried to implement this behavior with two separate Datagrid controls (only one control will be visible at a time), however, I faced lot of issues. Changes occurred in one grid have to reflect on other grid. I think its an indirect method. Can I achieve this by using single control.
I am not sure if you are familiar with Triggers, however I would suggest you to apply a Trigger to your Style based on the control's width property and change it's style the way you wish to be.
Here is a very good tutorial about Templates and Triggers from Josh Smith that you can learn from. In fact, have a look at all the parts of this tutorial if you want to learn more about WPF best practices.
A Guided Tour of WPF – Part 4 (Data templates and triggers)
Meanwhile since you're looking for a Trigger value to be a range rather than a certain value, say (Pseudo) Trigger when ListView's width < 300, you will need to use a custom converter with your trigger.
For an example of such converter look into this question
WPF Trigger when property value is greater than a certain amount

Display Different Views (Thumbnail,Details List) in Wpf from ListView in MVVM

I have a DataGrid that is displaying Data. I want to implement view switching functionality in WPF. I have read online and they say it's not possible with Data Grid .
There is also a topic that explains thumbnail view:
WPF: ListView with icons view?
But how to implement the same three view in the same control?
To be exact, I want the functionality like Windows Explorer where we can change the view from a dropdown list.
Some help in this regard would be great.
You are right. This is not something that the DataGrid supports. You can create your own views for the ListView, see the following article:
How to: Create a Custom View Mode for a ListView

WPF patterns: Items and ItemsSource

Well I'm designing a Custom WPF control - fore the sake of learning - that display logs message in a similar way Visual Studio does. I want to allow the user add messages by adding message istances to an Items collection, or by binding to an ItemSource. I think this is a well established pattern in many wpf controls, but I have no Idea on how achieve it. I know I can obtain the same result by adding a listview as a part of my control, but the project goal is learning, so I prefer avoid that solution. Any idea ?
Have a read around the ItemsControl, your custom control can inherit from an ItemsControl, or a derivative of it. If you create an ObservableCollection containing your items and bind that to your ItemsSource, then your list will be automatically updated. You can style the ItemTemplate and Template to give the list a different look and feel.
There's loads of info here

How to add Silverlight 4 ContextMenu to DataGrid row using XAML?

Silverlight 4 has a new ContextMenu control in the latest toolkit.
I can't find any examples anywhere on how to reliably use this ContextMenu on a DataGrid row. Theres a tonne of context menus out there but I want to use the new version from the toolkit.
I'd like to be able to set context menus for rows as well as cells.
The only way I've found is to manually create the menu on right click and show it, but I'd like to do it in XAML.
Note: You need to currently use this workaround to avoid binding problems when using ContextMenu in XAML for a datagrid cell.
The developer of the Toolkit's ContextMenu wrote this article, specifically talking about using it with a DataGrid Delay's Blog
You can use this open source multi-level menu and context menu as alternative:
www.sl4popupmenu.codeplex.com
The demo on the main page shows how to do it in code. But you can also create the menu anywhere in your XAML like any other control and then associate it with the Datagrid using the RightClickElements property. The control will then handle everything else for you.

Dynamically changing a WPF ListView between one that contains a GridView with column headers and another view that doesn't

I'm not quite sure how to go about this so any advice would be much appreciated.
I have a ListView whose default implementation is using with column headers. At runtime in the program I would like to be able to click on a button at runtime to change the view so that the list view loses the GridViewColumn headers and implements a new style using one of my own data template.
Then I would also like the ability to click the button and change the ListView back to a grid view with column headers.
Can anyone point me in the correct direction of how to go about this?
Thanks
Since ListView.View is dependency property, you can bind it to something on your VM via converter.
Microsoft has a sample that demonstrate how to create a ListView control that displays data in multiple view modes, which include the GridView and other custom view modes.
Search for ListView with Multiple Views Sample in the WPF Documentation Sample page.
http://archive.msdn.microsoft.com/wpfsamples
Here is a direct link to download the sample:
http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfsamples&DownloadId=7766

Resources