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”

Morse Coder Part 8 : Windows 10 Migration

I’m sure you’re probably all aware that Windows 10 is out, (if not in the news then the nagging to upgrade), I recently took the plunge and upgraded my PC and tablet and have to say I’m rather impressed.  Along with the Operating System I also upgraded my development environment to Visual Studio 2015 Community to start taking a look at Windows 10 Apps, (and maybe start dabbling in Xamarin now that it’s so accessible).  In light of this, now seems as good a time as any to start looking at implementing our Morse Coder App as a Windows 10 Universal App.

Outcome

Windows 10 Universal Apps differ from Windows 8.1 and Windows Phone 8.1 apps in that they require only a single Project for the UI, where the 8.1 apps would have had Windows, Windows Phone, and a Shared Project; Windows 10 requires only a single project.  By the end of this post we should have a functioning Windows 10 app, with all the current functionality from the existing Desktop Version, running on both the Phone Emulator and the Desktop (and everything in between).

Continue reading “Morse Coder Part 8 : Windows 10 Migration”

Morse Coder Part 7 : Data Binding User Controls

User controls offer a way to abstract common areas of your User Interface in a reusable package, allowing you to simplify your views and push some of the complexity of your UI into more manageable pieces.  This tutorial will focus on Data Binding to Properties on a User Control from a ViewModel.

Outcome

By the end of this post we should have a basic User Control bound against some Commands living in the MainViewModel to manipulate the content of the Input, in our case, we’ll offer a way to input Morse Code (dots/dashes) outside of needing to use a Keyboard in preparation for extending the App to translate both ways from the User Interface.
Continue reading “Morse Coder Part 7 : Data Binding User Controls”

Morse Coder : GitHub repo now available

The solution for my Morse Coder series of Universal App Tutorials is now available on GitHub:

https://github.com/mjcdev/MorseCoder

Have a look if you’ve been following the tutorials or are just curious.  I’ll be adding to this in alignment with the tutorials.

Hope it helps!

Morse Coder Part 5 : Unit Testing with the Microsoft Unit Test Framework

How do we know that our Morse Code Translation Logic is working correctly? This is where Unit Tests prove to be a valuable tool to have in our toolkit. There are a number of Test Frameworks available, NUnit, XUnit, etc. Given that we’re using PCLs targeting Universal Apps, our choices are limited slightly at this stage, so for simplicity and speed of getting up and running we can use the Libraries and Test projects bundled with Visual Studio. There’s masses of documentation and blog posts around Unit Testing and Test Driven Development (TDD) so I won’t go into the why’s here, but if you’re new to the concept I would recommend you read The Three Rules of TDD by Robert C Martin (Uncle Bob).

(If we were following strict TDD, these tests would have been written before we created the translators, but we’ll look past that for now!)

Continue reading “Morse Coder Part 5 : Unit Testing with the Microsoft Unit Test Framework”

Morse Coder Part 4 : Dependency Injection with MVVM Light SimpleIoc

To date, we have a functional, but basic set of Windows Phone and Windows Store applications which can translate Alphabetical Input to Morse Code. One of the key tenets of MVVM Light is the ability to inject design time services or functionality to provide a better design experience. We need somewhere to store our Application Settings, along with a means of setting and retrieving them, we won’t cover the implementation of this, but we will cover the creation of our interface and the implementation of a design time settings class.

Outcome

By the end of this post we will have, at design time, the ability to manipulate a settings class to be used with the designer in Visual Studio, or through Expression Blend. This will be done via an application settings interface detailing what data we need to store and of course what type it needs to be. As we are targeting multiple platforms, the interface, in a future post will be implemented to provide the storage of our settings per operating system.

One of the main benefits of using Dependency Injection to achieve this is that the implementation of our ViewModel is not concerned with where it retrieves information from and doesn’t need to make decisions depending on which context it is being ran in, this moves us closer to alignment with the Single Responsibility Principle.

Continue reading “Morse Coder Part 4 : Dependency Injection with MVVM Light SimpleIoc”

Morse Coder Part 3 : Data Binding with MVVM Light in Universal Apps

Data Binding can be used to dynamically bind information from a set of objects (View Model) to controls on a page (View). Following from the previous post, Morse Coder Part 2, we will be adding some flesh to the User Interface to take input from the user, process, in our case ‘translate’, and return output back to the user via our ViewModel.

Outcome

By the end of this post we should have a basic, but functional User Interface, taking a sentence from the user via a TextBox, and returning a Morse translation via a TextBlock. We’ll also start to consider Background Colour bindings. As before, this will cover both Windows 8.1. and Windows Phone.

Continue reading “Morse Coder Part 3 : Data Binding with MVVM Light in Universal Apps”

Morse Coder Part 2 : Portable Class Libraries with Universal Apps

Portable Class Libraries allow the reuse of code cross-platform, following from the previous post, Morse Coder Part 1, we will be implementing a very basic Portable Class Library (PCL), again targeting Windows 8.1 and Windows Phone 8.1.

Background

Portable Class Libraries provide a means of sharing code between Projects targeting different types at the Solution/Project level, they differ from Shared Code Projects in that Shared Projects share resources at compile time and compile as ‘part of’ their host project. You choose your Targets as part of the configuration of the Project, the result being a subset of libraries and namespaces being made available based on intersection of what’s available in the chosen Targets. We will be looking at Windows 8.1 and Windows Phone 8.1, this could be extended at a later date to include a number of other platforms, such as Silverlight, Xamarin, etc.

Continue reading “Morse Coder Part 2 : Portable Class Libraries with Universal Apps”