NumericTextBoxBehavior for XAML-based Windows Store Applications

One of the first (and arguably most useful) behaviors that I wrote for MVVMHelpers was a NumericTextBoxBehavior.  This is a WPF behavior that restricts the input for a TextBox to be numeric-only.  Recently, someone emailed me asking if it was possible to do the same thing in a Windows Store application.  It absolutely is, but there are some caveats. My original implementation for WPF utilizes preview events - these are events which are sent to the ancestors of the element prior to it receiving a … [Read more...]

Managing focus with MVVM in Windows Store Apps

One thing that is always troublesome in MVVM is focus-management. How can we push focus to a specific control during business logic processing and still keep a clean separation of UI and logic? There are likely several good solutions out there, but one I have used in the past is a Blend Behavior called SetFocusAction. I ported this behavior to the 8.1 Windows Store model (and it also exists in 8.0 as part of my full behaviors package with MVVMHelpers). Using it is pretty easy - let's pretend we … [Read more...]

ViewModel triggers

A question I often get is how to drive behavior through MVVM where the activity is actually initiated on the ViewModel side. It's easy to see the other direction - where the UI raises a command or property change to cause something to happen. I often use one of two approaches when initiating state changes in the UI from the ViewModel. The first is to use property changes - since Data Binding is all about property change notification, you can easily make property changes and cause things to … [Read more...]

Behaviors in Windows 8.1 Store Apps

Visual Studio 2013 RC was released to MSDN this week and it includes some very cool new features which have been detailed on various blogs around the Internet.  One feature I've not seen much coverage of, but am very excited about is support for Blend behaviors.  If you create a new Windows Store application using the 8.1 profile you will find Blend behaviors in the Assets tab: The list of behaviors is small - compared to WPF and Silverlight, but all the important ones are there, along with a … [Read more...]

Navigation and Persistence with MVVM in Windows Store Apps take #2

Earlier I posted on an updated version of MVVMHelpers with persistence support (see here). Paulo Quicoli, a long-time MVVMHelpers contributor, sent me a little code and a different way of managing navigation and persistence that he's been using. I thought it was quite elegant and asked if I could include a version in the library, which he graciously agreed to.  The result will be in the next release of the library - but I thought I'd introduce it here. The idea is to use a serializer on the … [Read more...]

MVVMHelpers for Windows 8 Metro

I've been doing some Windows 8 Metro programming lately and to help with building more testable applications have ported the MVVMHelpers ( over to Metro/.NET 4.5.  This post is intended to introduce the functionality and show it off a little. First, we'll create a new Metro-based Blank application using Visual Studio 2012: Next, let's add references to the MVVM library - we'll use NuGet, but you can also downloads the source or binaries from Codeplex.  Make sure you … [Read more...]

Unit Testing with services in MVVM Helpers

In the previous post I showed how you can easily replace services within your application to fit whatever your goals are.  This is also a requirement when you would like to unit test your application, but there’s a slightly different twist to it. As a simple example, let’s use the little demo app we built to play with service replacement.  In this case, our CalculatePi method in the MainViewModel ended up with the following code: private void OnCalculatePi() { IMessageVisualizer … [Read more...]

Replacing Services in MVVM Helpers

One of the key features in any good library is to provide a wide set of services for applications to use, but also some level of flexibility to replace those services when the built-in implementation aren’t what is needed. MVVM Helpers provides this capability using the Managed Extensibility Framework (MEF) which is built into .NET 4.0 and provided on for .NET 3.5.  MEF allows you to compose your application dynamically – looking up concrete implementations for … [Read more...]

Using the Message Mediator Service in MVVM Helpers

One of the services exposed in the MVVM Helpers library is a Message Mediator.  This service implements the mediator design pattern which is used to enable objects to talk to each other without having any explicit knowledge of each other.  In this pattern, we use a third-party object (the “mediator”) to negotiate communication between the interested parties. The message mediator is actually part of the JulMar.Core assembly – this is a general .NET assembly that contains useful code, … [Read more...]

MVVM: Rename TreeView nodes

I know I said I was going to cover some services next, but I got a request last night to show how to rename TreeView nodes (ala Explorer) using the MVVM pattern in WPF.  The solution is quite easy and elegant and I thought I’d share it here. First, the idea is we want to be able to double-click on the text portion of the TreeViewItem and have it allow us to type in a new name, replacing the current text.  This involves changing the visual template out (from a TextBlock to a TextBox) … [Read more...]