How to implement an editable listview in MVVM model? - wpf

I have an mvvm application...I need to have an editable listview.
I am binding my observable collection to listview.
How could I track changes of the values in listview ?...I mean if user edit an item...I need to have changed values in my observable collection.
If I use datagrid in WPFToolKit, is it easy ?

In a word, yes.
Take a look at data templates in WPF. They allow you to define how you want each item in your list (or any control) to appear and behave. So each item in your listview can one or more editable controls that are bound to each item in your collection (in this case an ObservableCollection). As you change data in the listview, the bound objects will in your collection will be updated in real time.
This is also possible with a datagrid.

Have a look at this link
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-3-in-place-edit
It is recommended you to use the Datagrid.It already provides the edit mode functionality. You can use a TemplateColumn to provide editing views.

if you have an editable Collection in your viewmodel, just take a datagrid(editable stuff built in). you can create styles or use templates so that the datagrid look the way you want.
If I use datagrid in WPFToolKit, is it easy ?
yes ;) but if you can, use the .net4 datagrid

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.

datarepeater like control in Silverlight?

I need some kind of control to wrap my UI (which generates using binding). Currently I use ListBox but not sure if it's lightest or best choice. I just need placeholder that I can bind to and insert my controls.
You're probably looking for the ItemsControl
You can use any control that takes a list of entities as it's data source.
This could be DataGrid, ListBox (as you are already using) or anything that inherits from ItemsControl - this includes things like the TabControl as well.

WPF and treeview: tricks with Items

I have some questions about treeview in WPF.
How can I change header of selected item?
How can I add child Items to selected item?
Use MVVM. In your HierarchicalDataTemplate, bind Header and ItemsSource to properties in your view model which implement change notification. Now any changes you make to those properties will be reflected in the TreeView.
If you're not using MVVM and data binding to populate the TreeView, you're wasting a lot of effort.
Robert is right, you should use MVVM and data binding. The tutorial that IMHO explained it best is here

Programmatic multi-select on the Silverlight DataGrid control

Is it possible to programmatically perform multi-select operations (eg. extend selection, remove selection) on the Silverlight 4 DataGrid control?
I didn't notice it at first, but the SelectedItems collection on the DataGrid is directly editable. So you can add/remove things on that collection directly to change selection.

Resources