Eager Instantiation of ViewModels with MVVM Light Messaging

Dependency registration in SimpleIoc, by default uses Lazy Instantiation, meaning the object won’t be created until it is requested, in this case, via the property on the ViewModelLocator class.

Due to configuring subscription of a message type in the Constructors of my ViewModels in MVVM Light I recently came across a situation whereby messages were being published prior to them having been subscribed to, meaning that the messages disappeared into the void unhandled.  The ViewModels relating to the pages I had navigated to were available in the ServiceLocator, but the pages that I hadn’t navigated to were not being instantiated.

Continue reading “Eager Instantiation of ViewModels with MVVM Light Messaging”

Universal App Tutorials Part 15 : MVVM Light Messaging

It’s often necessary to “inform” other areas of an application of changes that have occurred.  This can be achieved through Messaging.  In the previous tutorial we created a Settings page and made the TranslationDirection Configurable.  It would be nice if the Main View Model knew about our new Translation Direction setting, let’s look at how we can achieve this.

Outcome

By the end of this tutorial we should have implemented a SettingsChangedMessage, subscribed to it from our MainViewModel and Published it from our SettingsViewModel. Continue reading “Universal App Tutorials Part 15 : MVVM Light Messaging”

Universal App Tutorials Part 14 : Settings Page

Applications generally have a settings page, or similar allowing the user to configure the application.   We laid the groundwork for making the Translation Direction setting configurable in the previous post, let’s look at putting that in to practice.

Outcome

By the end of this tutorial we’ll have a really basic Settings Page, 2 Buttons allowing the user to pick between Morse to Alphabet and Alphabet to Morse, and a TextBlock displaying the current Translation Direction. Continue reading “Universal App Tutorials Part 14 : Settings Page”

Universal App Tutorials Part 12 : Universal App Reviews

One of the most compelling reasons to download an app is the number of Universal App Reviews in the store.  This tutorial will look at adding a Review App Button to our completely empty About Page.  There are various places you can surface the Review App Function, commonly it’ll be available on an About or Info page, or you may choose to have a Review Reminder.  As with a number of things with UWP apps, the Universal App Review Method changed slightly from Windows Phone 8’s MarketPlaceTask, let’s take a look…

Continue reading “Universal App Tutorials Part 12 : Universal App Reviews”

Universal App Tutorials Part 11 : Value Converters

One of the rules of using MVVM is that your model shouldn’t need to know anything about the UI Layer, and your View should be decoupled from the Model via the ViewModel.  It can often be necessary to have some form of conversion between what our Model understands and what the View would understand.  A common example would be converting a boolean flag to a Visibility State, this is where Value Converters come in.

Outcome

We’ll follow a slightly more domain specific example in this case, converting the TranslationDirection Enumeration Property to a Visibility State for our Morse Input User Control.

Continue reading “Universal App Tutorials Part 11 : Value Converters”

Universal App Tutorials Part 10 : MVVM Light NavigationService

Despite the rise in popularity of Single Page Applications (SPAs) and supporting frameworks like Angular in the Web Development world, it might be nice if we had more than one page in our app, or at least had the option to.  Our app so far is contained within a single page, MainPage.xaml.  A common pattern is to have different pages for Settings or Publisher contact information.  Navigation has moved on since Windows Phone 7.5 when it was URI based, we will look at how it now works with Universal Apps with typing and the MVVM Light implementation of INavigationService. Continue reading “Universal App Tutorials Part 10 : MVVM Light NavigationService”

Morse Coder Part 9 : Visual State Triggers

Intro

As we saw when we migrated our Universal Windows App to Windows 10 targetting Phones and PCs with the same set of markup presents us with a challenge…

Windows10-Phone.png

This UI is less than usable!  There are a new set of User Controls made available as part of Windows 10, for example the Relative Panel.  In this post we’ll look at ways we can make our UI adaptive based on the screen size we are targeting.

Outcome

By the end of this post we will have a single app that is usable on PCs, tablets, and Phones.  We’ll be looking into Visual State Triggers in order to alter the size of the text presented in our Input and Output TextBox and TextBlock controls.  Visual State Triggers apply transformations to the base XAML defined, we’ll be using this method to make our app responsive.

Continue reading “Morse Coder Part 9 : Visual State Triggers”