If you don't want to complicate things you can always just respond to the MouseDown event in your view's code behind. Here you have access to your ViewModel (via the DataContext) so can 'tell' your ViewModel to perform some action (whether via a command or a property or method - whatever works for you)
Currently I am facing problem in List View that, when we re-size the GridViewColumnHeader to the leftmost(width =0),not able to enlarge that column.It's not accessible later.I want to do this functionality as same as DataGrid. In DataGrid, it wont allow user to resize the column to width zero.
How can we acheive this functionality in ListView?
Just an FYI to the OP (and POH), I implemented MinWidth and MaxWidth on my own custom ListView and while the guys over at SO say "it works", I can tell you from personal experience it is an incomplete solution . There are a lot of little nuances you have to handle that the posted solution does not.
Beyond just dragging the splitter around, there is also the splitter double-click column auto-size behavior that needs to be patched, dragging columns (re-ordering) around screws things up, and the one that took me quite a while to solve: in a specific usage scenario (I forget the exact details since it's been a while), but it was something like where if you had the columns big enough so you had a horizontal scroll bar, and then did the column resize / auto-resize so it shrunk down the columns to where the scroll bar went away, the ListViewItems would not be resized properly and the control rendering would get all messed up.
This feature was actually a real PITA to get working properly in all cases. It ended up being several HUNDRED lines of code.
The standard way to do this is to expose a boolean property from your ViewModel that indicates whether or not the items the StackPanel represents are visible or not (I have worded this carefully so that you don't get the idea that the boolean maps to the StackPanel in anyway). This property must raise the PropertyChanged event when it changes. Then, in your View, bind the StackPanel Visibility to this property; as you are aware, the Visibility property is not a boolean property, so you use the BooleanToVisibilityConverter[^] to convert between the boolean value and the Visibility of the object.
I have to assume you know how to add the code into your ViewModel, so it looks like the bit that you are confused about is what happens in the XAML. Well, in your user control, add the following into the UserControl.Resources section:
If you are gonna do that, you might as well just expose a Visibility property from the VM and cut out the middle man. EDIT: unless that bool would be used for various things besides visibility I mean .
There's an implication there, though, that your testing code is going to bring in a reference to System.Windows for something that really isn't needed. The converter method keeps your VM test code 100% plain POCO with no WPF dependency.
Hi, I have just started working on MVVM, MVVM is new for me, this stackpanel visibility i have to show/hide on button command. Can you please provide any idea how to show/hide on button command from view model.
I already have. All the pieces are there. You hook up a command - you set the boolean property and then you raise the PropertyChanged event. As long as you have this view model hooked up to your DataContext, and you use the XAML I showed, you should be good to go.