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

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

Related

Custom Items control Approach

I need to build a custom items control in WPF, where the user can drag/drop the items. Normally I would just maintain a list of view models and use a data template to define how the items should be displayed (in this case, a button). But I am concerned that this will make the drag/drop difficult as the ItemsSource objects will be view model objects , not the actual button.
My other potential approach is when an object is added to the ItemsSource, create a button in c# and add it manually, that way I can access the button directly to do drag/drop.
What would your advice be?
I have solved my issue. I found a way to get the control being render from the data template

PropertyGrid-like multiselection in other elements(listView)

i want to immitate the behavior of multiselection of items (eg. in a list view) and their appearence in a PropertyGrid. So, obly the same properties are shown and values set in the grid are set on all multiselected properties.
I have created a listview with some datatemplates and have in another listview some data(with databinding). Now i want wo have a multiselection on the listview with the data and have the properties shown in the another listview like in a propertygrid.(explanation: The ProprtyGrid is still not available in WPF and if has not the flexibility of showing data the way i need it)
So, how do i need to prepare my data to be shown in the list propertygrid-multiselection-style? Is that even possible???
Greets,
Jürgen
I'm not sure if this question is still active, or what not. But I have found a solution that works for me - and I need somewhere to share it.
The first issue you are going to have solve is selecting the items, ie. multi-select. See my tip here that explains how to do that.
Next, I guess its basically binding to listview's selectedItem property and how you want to update your propertyGrid based on changes to the selectedItem prop.
Hope this helps.

Dynamic child user controls MVVM

I have a user control on a page and I'd like to load another custom user control within it's grid. However I want the user control type to be dynamic - e.g selecting "Calculator" from a drop down list would display my custom calculator control and selecting "Currency Converter" would load my currency converter. Can anybody help?
By the way I am trying to stick to MVVM.
Thanks in advance.
One way is to define multiple DataTemplates one for each child. As user selects the option set the corresponding ViewModel to a ContentControl's DataContext present in parent view and framework will pick the corresponding view for you.
John Papa has written a great blog post on exactly how to do this here.
The basic strategy is to instantiate a new instance of a class that derives from UserControl once selected from the drop down.
In other words, the SelectionChanged event of the drop down list could be handled and a new UserControl object created based on the selected item.

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

Adding filter textbox to header of a Listview in Gridview mode

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...

Resources