background preloader


Facebook Twitter

6: Advanced MVVM Scenarios. The previous chapter described how to implement the basic elements of the Model-View-ViewModel (MVVM) pattern by separating your application's user interface (UI), presentation logic, and business logic into three separate classes (the view, view model, and model), implementing the interactions between those classes (through data binding, commands, and data validation interfaces), and by implementing a strategy to handle construction and wire-up.

6: Advanced MVVM Scenarios

Implementing the MVVM pattern using these basic elements will likely support many of the scenarios in your application. However, you may encounter more sophisticated scenarios that require the basic MVVM pattern to be extended or that require more advanced techniques to be applied. This is more likely to be true if your application is large or complex, but you may also encounter these scenarios in many smaller applications. This chapter describes some sophisticated scenarios and describes how the MVVM pattern can support them. CanExecute. C# - WPF MVVM Modal Overlay Dialog only over a View (not Window) I'm pretty much new to the MVVM architecture design...

c# - WPF MVVM Modal Overlay Dialog only over a View (not Window)

I was struggling lately to find a suitable control already written for such a purpose but had no luck, so I reused parts of XAML from another similar control and got make my own. Custom popup and windows in WPF the MVVM way. In WPF, using the regular window control to launch child windows makes MVVM and separating a View concern from the ViewModel very difficult.

Custom popup and windows in WPF the MVVM way

The problem: The window control works nicely as a shell for your application, however, launching child windows is problematic because the window control cannot be defined in xaml unless as the root element. So, if you wanted to launch child windows inside a parent window, you lose the ability to declare these in xaml. This loss means you will not be able to bind to properties in your ViewModel from the view for the purpose of opening/closing a window. Instead you end up doing this imperatively in code which means more code, more thought, more work.

Following is what you end up doing in the most minimalistic cases. MyWindow window = new MyWindow(); window.ShowDialog(); Adding code such as the above means you are forced to make your ViewModel create instances of your Window and launch them when needed. <ResourceDictionary The main window : That's it.


MVVM Communication among ViewModels. When a new person enters into the MVVM world ,the first doubt in his mind would be ‘How can I achieve messaging among View-Models ?

MVVM Communication among ViewModels

’or ‘How to notify other ViewModels about a change or operation in one ViewModel ?’ For example if we take a scenario of CRUD database operations there should be notifications passing through on each operation like creation,deletion etc...Otherwise the listing ViewModel will not be up to date. When the same view-model communication came in to my mind, the possible solutions I got are Events : Raising events on operations so that subscribed view models will get notification.

Data access layer / Data repository / Data provider owns events View models own events. 1.Events Events at data layer The sample contained in the Josh Smith’s article uses this method.Events are written in the data layer and will be fired as soon the operation completed successfully. Events at ViewModel level 2.Mediator pattern. THE MODEL-VIEW-VIEWMODEL (MVVM) DESIGN PATTERN FOR WPF.

Patterns WPF Apps With The Model-View-ViewModel Design Pattern Josh Smith Developing the user interface of a professional software application is not easy.


It can be a murky blend of data, interaction design, visual design, connectivity, multithreading, security, internationalization, validation, unit testing, and a touch of voodoo. Considering that a user interface exposes the underlying system and must satisfy the unpredictable stylistic requirements of its users, it can be the most volatile area of many applications. There are popular design patterns that can help to tame this unwieldy beast, but properly separating and addressing the multitude of concerns can be difficult. It is not always the design patterns at fault.


Simple ViewModel Locator for MVVM: The Patients Have Left the Asylum - John Papa. I’ve been toying with some ideas for MVVM lately.

Simple ViewModel Locator for MVVM: The Patients Have Left the Asylum - John Papa

Along the way I have been dragging some friends like Glenn Block and Ward Bell along for the ride. Now, normally its not so bad, but when I get an idea in my head to challenge everything I can be “interesting” to work with :). These guys are great and I highly encourage you all to get your own personal Glenn and Ward bobble head dolls for your home. Working with a simple ViewModelLocator from MVVM-Light. <phone:PhoneApplicationPage x:Class="ItemList.MainPage" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:MVVM="clr-namespace:ItemList.ViewModelLocator.Framework.Implementors.Silverlight.MVVM" mc:Ignorable="d" FontFamily="{StaticResource PhoneFontFamilyNormal}"

Working with a simple ViewModelLocator from MVVM-Light

MVVM Animation by DataTrigger. Greetings, I would like to visually show when a background process is working.

MVVM Animation by DataTrigger

This process happens at a regular intervals (say every 30 seconds), and might take 10ms or 1000ms+ to complete. I'm using MVVM-Light framework so have created a data trigger wired up to a view model property on an image of a heart fading in and out. My amateur animation technique is working when the process takes a second or more, but I would also like it to complete a full heartbeat (2 repeats) when the process takes a short period of time (<100ms), otherwise the animation is over too quickly and you can't (visually) tell that the process is working.

The problem is that the heart should remain beating for the duration of the process, so I can't just set the repeat behaviour to 2. And if anyone has any tips on how to improve the heartbeat animation, I'm open to suggestions, thanks!