mvvm

WPF -- Where do you draw the line between code and XAML?

I'm a long-time C#/.NET programmer but totally new to WPF and the System.Windows.Controls namespace and XAML. The more I learn about it the more I realize that you can do pretty much all of your GUI initialization and event handling glue in either XAML or in code (say C# code or VB.Net code). My question is to those who have been wo...

Loosely coupled events in WPF without using Prism

I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application consists of two modules at the moment: Left Panel to browse a tree and select a node Main Panel to show the content of the selected tree node. I want to keep these two modules seperated, but when I select a node in the Left Panel I need t...

Should I Keep Business Objects Separate from the UI in WPF?

WPF's view model oriented way of doing things makes it very tempting to just use business objects in the UI. Have you seen any issues with this? Why or why wouldn't you do this? ...

ViewModel on top of XDocument

I am working on a WPF application which has a treeview that represents an XML. I load the XML on to the XDocument, then bind the TreeView to this object. Now using the MVVM pattern, I want to provide a ViewModel on top of XDocument. What are some of the things that I should implement in the ViewModel class. I am thinking of, Routed...

What applications could I study to understand (Data)Model-View-ViewModel?

I understand the basics of the Model-View-ViewModel pattern or as Dan Crevier calls it the DataModel-View-ViewModel pattern and I understand that it is a good approach to design WPF based applications. But there are still some open question. For example: Where do I put my business logic where my validation logic? How do I decouple the ...

Using data binding to launch animations in WPF

I am trying to adapt a simple WPF application to use the Model-View-ViewModel pattern. On my page I have a couple of animations: <Page.Resources> <Storyboard x:Name="storyboardRight" x:Key="storyboardRight"> <DoubleAnimation x:Name="da3" Storyboard.TargetName="labelRight" Storyboard.TargetProperty="Opacity" From="0" To="1" D...

INotifyPropertyChanged vs. DependencyProperty in ViewModel

When implementing the ViewModel in a Model-View-ViewModel architecture WPF application there seem to be two major choices how to make it databindable. I have seen implementations that use DependencyProperty for properties the View is going to bind against and I have seen the ViewModel implementing INotifyPropertyChanged instead. My quest...

How does the Presentation-/ViewModel for a Task or Dialog look like?

I'm trying to move to a Model/ViewModel/View architecture and got stuck when trying to push selection dialogs to this pattern. I'd like to separate retrieving a list of choices (business/presentation logic) and the actual displaying/choosing mechanism (view) to re-use the former with different views (e.g. ComboBox vs. modal dialog). How...

M-V-VM Design Question. Calling View from ViewModel

I've just started looking into M-V-VM for a WPF application. Everything makes sense so far besides this particular issue... I have a ViewModel I'll call Search. This ViewModel binds to a datagrid and lists results of items. Now, I have a command that needs to bring up another view, the item's details. Putting the logic to show anoth...

Model-View-Presenter and Modal Dialog boxes.... How to?

I am implementing MVP/M-V-VM in WPF and I'm having good luck with it so far. However, I don't see how this model supports implementing Modal dialog boxes. I've derived my work from Crack.NET (http://www.codeplex.com/cracknetproject) to learn how this stuff works. I have a ShellView view (which is just XAML) that has a menu on it. The...

why not partial class to build the ViewModel in MVVM pattern?

Why not use partial class to build the ViewModel? Since the definition of viewmodel classes have some definition of the data classes of datamodel, why not try to reduce some work, extending or making partial classes of the datamodel, completing them with command and etc. ...

Using IDataErrorInfo in M-V-VM

If my domain objects implement IDataErrorInfo, and I am using M-V-VM, how do I propagate errors through the ViewModel into the View? If i was binding directly to the model, I would set the "ValidateOnExceptons" and "ValidateOnErrors" properties to true on my binding. But my ViewModel doesn't implement IDataErrorInfo. Only my model. What ...

What is the best approach to binding commands in a ViewModel to elements in the View?

Anyone who has tried to implement RoutedCommands in WPF using M-V-VM has undoubtedly run into issues. Commands (non-UI commands that is) should be implemented in the ViewModel. For instance if I needed to save a CustomerViewModel then I would implement that as a command directly on my CustomerViewModel. However if I wanted to pop up a wi...

Silverlight Databinding - Binding a ValueConverter to a property on a view-model

Let's pretend I have the following xaml... <UserControl.Resources> <local:ViewModel x:Name="viewModel" /> <local:LoadChildrenValueConverter x:Name="valueConverter" /> </UserControl.Resources> <UserControl.DataContext> <Binding Source="{StaticResource viewModel}" /> </UserControl.DataContext> <Grid x:Name="LayoutRoot" Bac...

Two 'self-updating' properties in WPF MVVM

Considering you have an MVVM Architecture in WPF like Josh Smith's examples How would you implement two properties 'synced' that update eachother? I have a Price property, and a PriceVatInclusive property in my model. -When the Price changes, I want to see the Vat inclusive price to automatically be 'Price * 1.21'. -Vice versa, when...

Should I use the Model-View-ViewModel (MVVM) pattern in Silverlight projects?

One challenge with Silverlight controls is that when properties are bound to code, they're no longer really editable in Blend. For example, if you've got a ListView that's populated from a data feed, there are no elements visible when you edit the control in Blend. I've heard that the MVVM pattern, originated by the WPF development comm...

Dependency Properties with Explicit Interfaces

Hi all, I am knocking together a WPF demo for our department at work to show them the advantages of WPF whilst trying to adhere to our development standards (dependency injection and developing objects to an explicit interface). I have come to a bit of a wall now. I am implementing the View using the MVVM design pattern and I need to u...

Good Silverlight-MVVM Practice Example

I've read a number of good articles about the Model-View-ViewModel pattern and my team intends to implement this pattern in the latest version of our app. I still don't quite get ALL the bits that go together to make this work. I'd like to find a good example of this pattern that I can work through. Something on a small scale, much li...

Model - View - ViewModel & WCF - is WCF the model?

I'm just learning the Model / View / ViewModel pattern and it's variations (DataModel / View / ViewModel, or Model / View / Presenter). What I wonder is: if I use this pattern with a WCF service, is the service the Model (DataModel), or do I need a separate Model to encapsulate the WCF service layer?? When I use WCF as DataModel my Vie...

M-V-VM - Any Examples of using commands in the ViewModel?

I've been developing a very large LOB app using my flavor of M-V-VM which I call M-V-MC (Model-View-ModelController), which is a kind of a combination between M-V-C and M-V-VM. I had posted this answer regarding how views get instantiated in M-V-VM to the question "what-are-the-most-common-mistakes-made-in-wpf-development". Sam made the...