mvvm

MVVM Pattern, ViewModel DataContext question

I need to figure out how to communicate between ViewModels. I'm new to MVVM so please be kind. Here's a dumbed down example class definitions(assume that I have hooked the Child.PropertyChanged event in the ParentViewModel): public class ParentViewModel : ViewModelBase { public ChildViewModel Child { get; set; } } public class Ch...

How to present a Collection of (View)Models in a ViewModel

Hi. I have a question regarding the MVVM design for C#/WPF. I've had a look at several demo applications, but they didn't really handle my problem. My application consists of objects that contain other objects. Much like in a parent - children relationship. My question now is: does the children attribute have to be a ViewModel and ...

Composite Guidance for WPF : MVVM vs MVP.

Hi, I am confused. Maybe you can help me :) I have been following the guidance of CAG and found the MVP pattern very natural to me. Suppose I have a UI-ready Model (for example : implements INotifyPropertyChanged), I use the presenter to bind this Model to a view (presenter knows an interface of the view), keeping my Code-Behind as sma...

Using MEF to import a WPF DataTemplate?

I was looking at MEF as an extensibility framework, and I'm pretty much sold, except for one point: Let's say I want to import both a ViewModel and a View to display it. I think the "right" way to do that is for the MEF part to export a ViewModel class, and a DataTemplate that displays the ViewModel. As an example, say you were buildi...

WFP MVVM: Good reasons *not* to place VM's in separate assembly?

I'm developing a project using the MVVM pattern in WPF. One of the key benefits to MVVM is maintaining clear separation between business logic and presentation. As a test to see how well separated everything actually was, over the weekend I spiked moving all ViewModels, Models, and business logic to a separate .dll. The .exe was left ...

MVVM and window lists

I'm writing an app that lets users browse through data, and I want to use the FireFox UI style: allow the user to open as many windows as they want, each with as many tabs as they want. I also want to try to do this using the Model-View-ViewModel pattern as much as possible. Opening a new tab should be easy enough to handle in MVVM. Mak...

WPF MVVM : Commands are easy. How to Connect View and ViewModel with RoutedEvent

Hi Suppose I have a view implemented as a DataTempate inside a resource Dictionary. And I have a corresponding ViewModel. Binding Commands are easy. But what if my View contains a control such as a ListBox, and I need to Publish an application wide event (Using Prism's Event Aggreagtor) based on the Item being Changed on the List. if L...

Where is the best place to put Business Rules in a Silverlight MVVM RIA Services application?

Where is the best place to put business rules in an RIA Silverlight application? I thought the Domain Service would be a good spot except it seems to only share Data to the client tier. I don't think the ViewModel is a good idea since we should have Business Rules in the server tier. In shared code? *.shared.cs? Where do you put your ...

Get DataContext of ListView Ancestor

I am developing a WPF app using MVVM and need some help. for the View of my AddressesViewModel I have a usercontrol with a listview. I would like to execute a command found in the AddressesViewModel from the contextmenu of the listViewItem. Because I'm opening a ContextMenu it is not found in the visual tree(I read that somewhere). He...

Fat Models, skinny ViewModels and dumb Views, the best MVVM approach?

Through generous help on this question, I put together the following MVVM structure which displays the changes of a model in real time in XAML (current date/time), very nice. A cool advantage of this set up is that when you look at your view in design mode of Visual Studio or Blend, you see the time ticking by, which means th...

Undo journaling: focusing the control being undone

I'm writing an undo journal for my WPF data-entry screen, which will track changes across all the controls. When the user selects Undo, I want to not only revert the latest change, but put focus back in the control whose value is being reverted. I'm struggling with the best way to put that focus back. My ViewModel will be the part that ...

Is it ever too late to implement an architectural pattern such as MVC or MVVM?

I've been unleashed on version 2 of an application my company has been working on. It was our first foray into WPF and needless to say, a lot of lessons were learned. The product took a year to develop, so it's not a small application by any means. Everyone recently came on board with MVVM. Now that we have a large code base with ple...

How to merge menu with WPF MVVM?

The default MVVP I have seen has multiple ViewModel objects that are rendered through data templates. Each ViewModel exposes commands via their own properties. I would like to merge ViewModel commands with the menu so when different tabs are selected, the menu changes based on what the ViewModel does. What would be the best way to do ...

Big smart ViewModels, dumb Views, and any model, the best MVVM approach?

The following code is a refactoring of my previous MVVM approach (Fat Models, skinny ViewModels and dumb Views, the best MVVM approach?) in which I moved the logic and INotifyPropertyChanged implementation from the model back up into the ViewModel. This makes more sense, since as was pointed out, you often you have to use models that you...

In MVVM, what is the best way for the ViewModel to respond to user actions in the View?

I understand that in MVVM: the View knows about the ViewModel the ViewModel knows about the Model but it doesn't work upwards, so the Model knows nothing about the ViewModel and the ViewModel knows nothing about the View So how does the ViewModel respond to actions that the user does on the View, e.g. type something into a TextBox or...

What are the best characteristics of a datalayer framework for WPF/MVVM applications?

I am creating a WPF/MVVM framework which generates the code for the model classes. I'm planning to have for each database-table/web-service (e.g. "Customers") two model classes: a singular model class (e.g. "Customer") and a plural model class (e.g. "Customers") The singular model class has all of its properties (FirstName, LastNam...

Confusion with WPF MVVM

I have downloaded the document about MVVM from CodePlex, but I don't understand this diagram. In the document, ContactView never sets its DataContext to ContactViewModel, so I don't understand why this diagram has shown that ContactView refers to ContactViewModel via DataContext. I don't know when it sets ContactView.DataContext, or ...

WPF: How to attach mouse events to a viewmodel?

I am trying to use the MVVM pattern for the first time. So I have an ItemsControl filled with my viewmodel objects, displayed using DataTemplates; the objects are "nodes" and "edges" represented in DataTemplates with Thumb and Polyline objects, and I want to be able to detect clicks and drags on the ItemsControl in order to move the node...

MVVM radiobuttons

Someone please help. I have an interesting issue. I am trying to implement an MVVM app and I want to bind to radiobuttons in my view. Here's my view: <StackPanel Orientation="Horizontal" Grid.ColumnSpan="2" > <RadioButton GroupName="1" IsChecked="{Binding Path=NoteGeneral, Mode=TwoWay}">General</RadioButton> <RadioButton Grou...

What are the problems of the MVVM pattern?

Is Model-View-ViewModel the best pattern to use in WPF? Are there any downsides? ...