.net - WPF MVVM - Command binding inside of an ItemsControl -


I am currently converting a small WPF project into MVVM. I have a list in the ViewModel of the main window & lt; Custom Object & gt; that my item tool binds a datatomplate to create the UI of each element and uses it my old code used an event handler inside the data template to handle one click event. I want to use some type of command binding to eliminate the event-handler of my code-behind, but my items are the datacentext model object of the items in control, so I can not currently bind to an ICommand from ViewModel.

So, I think there are some ways to attack it and I'm not sure that this will be the most "MVVM" way of doing this. Do I bind itemsControl.ItemsSource to a new ViewModel class collection that represents each item? Or is I using UserControls instead of a DataTemplate, and then I can force each UserControl with it's own example of ViewModel, which shows it? Or is there any type of compulsive expression that I can use to see the backend of the window's datacentext, which can be used to bind the view modal (as I type it, it just sounds bad So, I consider it a big "no" idea)?

Besides, what I want to do to bind my order is a Grid Control LeftMouseButtonUp event is not "command" for a grid, so I was trying to use InputBindings. Could use a stationary command (such as one in one of the built-in application commomities), but I can not use bindings expression with an icmand frequency which is a property of ViewModel Because of the mousebing. Commodity is not a dependency property.

I am very confused about the event handling in MVVM, so any and all information is appreciated.

Do I have to control items. Bind the ITemsource into a new Videodel class collection that represents each item?

Do you create a custom object view model to host commands or locations, the command within the same visual model, which is in the list depends on the actual action taken. Is there anything that is with custom object, or is it something that is with your current view model?

or any type of binding expression that I can use to referenced back to the window's datacentext ViewModel (like I type it, it just looks bad, so I think this Can I use the idea of ​​binding for the idea to be big "no"?

It is not as bad as it seems that you do not really need a window's datacentext, it was switched off to different items just before datacontax. So if your order was on the same view modal that hosts the list of custom objects, then you can force it from within the custom object datatappletlet using one of these methods:

  {Binding element name = uiCustomObjectsItemsControl, Path = DataContext.MyCommand} {Binding relative Soros = {Reslevissor Mode = SearchInstaster, Instant Type = {x: Type ItemsControl}}, path = Data Contains. My Command}  

In addition to this, what do I want to force my command to the left mouse button of a grid control I do not have a "command" for a grid, so I was trying to use inputbindings.

For this, I will use something like that so that you can attach the ICOMMend for any event.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -