We’ll start with the XAMLs for this project. Although this is actually a straight forward task, there are a couple of issues that one should keep an eye on.

As a reminder – this is what we want:

You could now start with a window and put the buttons in there. But it’s a better approach to put (almost) everything in UserControls. UserControls can be used everywhere – in Windows, in Pages, in other Controls, in Templates etc., so this is a much more flexible approach.

That brings up the first suggestion:

Suggestion #1: Put (almost) everything in UserControls

And there is another reason: When you start working with DataTemplates, you will recognize that you can’t preview them in Visual Studio, simply because you’re just defining a template and not a control or a window, so there’s actually nothing to visualize. When you put your XAML in a UserControl you can edit the UserControl instead of the DataTemplate and change the DataTemplate to simply use the UserControl. You’ll see how this works.

So, let’s start with a new UserControl; name it MainMenuPage. Put a stack panel and four buttons in it:

To be able to test this control, put it in the main window:

That looks like this:

But we want a couple of things to be different: a colored background, bigger font size, bigger buttons, etc.

We could now put these properties in the attributes of the buttons. That would look like this (in the worst case):

That looks very messy. And it will be lot of work if you’d want to change the font size for example. (And you will have to change it because customers constantly change things…)

This is the next suggestion:

Suggestion #2: Use Styles and Templates from the beginning

While it is a little more work to define styles instead of putting attributes directly in the XAML files, it will pay off in the long run, because centralized styles are very easy to change. The other thing is that XAMLs get very messy over time, if you put everything in attributes. And it really speeds up prototyping when you can rely on a set of standard styles and don’t have to think of styling all the time.

Putting the style into the App.xaml…:

…and referencing this style in the stack panel…:

…looks a lot nicer.

We’re almost there. The “AntiqueWhite” background is still missing (and the padding).

Put a border around the control…:

…and define a style in App.xaml for it:

That’s it for now.

Next step: SimpleMVVM, Part 2: The product edit and customer edit pages