Building a Classic Tabbed and Databound Desktop Application with UWP and MVVM

What kind of business applications do you build? Do they have a tabbed user interface? Most of mine do so.

After spiking (=prototyping) the Visual Studio Shell I wanted to go deeper into building a tabbed user interface with UWP, of course databound with MVVM.

As you might know, UWP does not contain a TabControl. But it contains a Pivot-Control that has pretty much of the functionality needed for a classic tabbed UI. So, let’s go with the Pivot and let’s see how far we can get. (more…)

Lessons learned from Building a Visual Studio Shell with UWP

Note: There’s a MS Dev Show Episode where @ytechie, @carlschweitzer and I are talking about UWP and the Visual Studio Shell built as part of this post. You find it here on www.msdevshow.com

UWP is the technology to build native applications for the Windows Platform. But there’s still some stuff missing that is required by a typical line-of-business application for the classic desktop: TreeView, DataGrid, Validation, SqlClient and more. Some parts like a DataGrid are available as 3rd-party controls. Other parts like the TreeView are already in development, as you can see in the Windows Dev Platform Backlog. That backlog shows that Microsoft is working on a TreeView, which is awesome! And I’m pretty sure, at some point in the future we’ll also get a DataGrid. This was the case for WPF and also for Silverlight. But let’s see, the future will tell us and for today we’ve great 3rd-party DataGrids.

But what else is required to build a classic desktop application? (more…)

UWP: The Master-Detail-Problem with the events SelectionChanged & LostFocus and How to Fix it

While creating apps with the Universal Windows Platform (UWP) I noticed a weird behavior, but I’m not sure if it’s a bug. Let’s just call it the “Master-Detail-Problem”.

To explain it, I stripped  down my code to the XAML-snippet below. No code-behind needed. (more…)

BASTA! Spring 2014 – slides and demos

At this year’s spring edition of the BASTA! Conference (http://basta.net/2014se/) I gave three talks:

  • Windows 8.1 – UI Neuerungen
  • All you need to know about XAML
  • Asynchronous Programming with C#

Thanks to all the people who joined my sessions. I hope you liked them. If you’ve any feedback to share with me, feel free to contact me via this link.

You can download all slides and demos here:

Thomas talks

It’s there: Windows Store Apps with XAML and C#– the ultimate handbook

Wow, it’s done. The ultimate handbook about Windows Store Apps with XAML and C# is printed and available. You can order your copy of the German-written 1146-pages-book on amazon:

Amazon.de: Windows Store Apps – das umfassende Handbuch

Find more information about the book on amazon, on my homepage http://www.thomasclaudiushuber.com/windowsstoreapps and on the publisher’s website on www.galileocomputing.de/3196.

Training on Windows Store Apps

In Germany, Switzerland and Austria I’ll give a three-day-training on Windows Store Apps. If you or your company have interest on this professional training, directly contact me via http://www.thomasclaudiushuber.com/contact.php. It is possible to train you in the Trivadis-Trainings centers or onsite at your office.

So far so good, let’s look at the past and the future

The past

Puh, this was year was really instensive. Here the straight plan I had so far:

  • January: Buy new home
  • February: My second daughter Sara was born.
  • March: Finish the manuscript for the book
  • April:Renovate and improve new home (thanks to Makita Zwinkerndes Smiley)
  • May: Move
  • … in all months: Working as a consultant and trainer @Trivadis.

The future

So the future contains much more spare time, it’s necessary, because I say “Time is money is not true, time is unpayable”. I want to spend as much as I can with my kids, my wife, family and friends (See also this awesome post from Tim on that topic). So the future plan looks like this:

  • June: Finish a WPF-project as a consultant and enjoy the free weekends
  • July: Parental leave Smiley
  • August: Parental leave Smiley
  • September: Back to work, speaking at basta (www.basta.net) and at Trivadis-internal TechEvent

Keep on rockin’
Thomas

Windows Store-apps: WinRT XAML vs. Silverlight XAML

This post is part of a series about creating Windows Store-apps with XAML and C#. Find the Content of the series here:
Windows Store-apps with XAML and C# blog-series

Last weekend I’ve finished the XAML-chapter of my upcoming book about developing Windows Store-apps with XAML and C#. I want to share the things that you should know about the WinRT XAML – the way I call it here – if you’re familiar with Silverlight or WPF.

The WinRT XAML is much like the XAML we know from Silverlight. But there are some differences in WinRT XAML:

  • the way you use your custom namespaces is different
  • there are some missing things (TypeConverters, Custom MarkupExtensions)

Let’s look at the two parts

Use custom namespaces

There are two ways in XAML to use a namespace:

  • 1:1-Namespace-Mapping
  • 1:n-Namespace-Mapping

Read the difference for both in Silverlight- and WinRT-XAML below.

The 1:1-Namespace-Mapping

Let’s assume you’ve the following class:

namespace UIRocker.Special
{
  public class WindowsEight
  {
    public bool IsGreat { get; set; }
  }
}

To use this class in Silverlight-XAML, you’ve to add an Namespace-Mapping like this

xmlns:rocker="clr-namespace:UIRocker.Special"

or like this if the CLR-Namespace is in another assembly than the XAML-file containing the Namespace-Mapping below: 

xmlns:rocker="clr-namespace:UIRocker.Special; assembly=UIRockerLib"

With the Namespace-Mapping the classes from that Namespaces can be used with the chosen alias. The alias is “rocker” in the snippets above, so the WindowsEight-class can be used as below:

<rocker:WindowsEight IsGreat="True"/>

In WinRT-XAML you’re using the class in the same way as above, but the way of creating the Namespace-Mapping is different. Instead of using the syntax with “clr-namespace…” you use:

xmlns:rocker="using:UIRocker.Special"

You don’t care if the Namespace UIRocker.Special is in another assembly as the XAML-file or not. This works exactly the same way as the using-directive in C#, where you also don’t care if the Namespace is in another assembly than the .cs-File or not. So, great improvement, but creates a little incompability with Silverlight-XAML.

The 1:n-Namespace-Mapping with XmlnsDefinition-Attribute

The Namespace-Mappings above have been 1:1-Mappings. One XML-Namespace was mapped to one Silverlight/WinRT-Namespace.

In Silverlight-XAML you can create a 1:n-Namespace-Mapping by placing the XmlnsDefinitionAttribute (Namespace: System.Windows.Markup) on your assemblies like this:

[assembly: XmlnsDefinition(
 "http://thomasclaudiushuber.com/","UIRocker.Special")]
[assembly: XmlnsDefinition(
  "http://thomasclaudiushuber.com/", "UIRocker.Mvvm")]

Classes out of the Namespaces UIRocker.Special and UIRocker.Mvvm can be used in XAML with one alias by making a 1:n-Namespace-Mapping like this:

xmlns:rocker="http://thomasclaudiushuber.com/"

Unfortunately in WinRT-XAML there is no possibility for a 1:n-Mapping. The Namespace Windows.UI.Xaml.Markup contains a XmlnsDefinition, but it’s not an attribute, it’s a struct and therefore not usable.

Especially when you create a library with many Namespaces in it, it’s great to use just one alias for the library in XAML. Maybe the next Version of WinRT will contain such a mapping. By the way, first versions of Silverlight also didn’t support 1:n-Namespace-Mappings.

Missing things in WinRT-XAML

There are a few other things that are not in WinRT-XAML or behave differently. Let’s take a look at them.

Typeconverters

As XAML is XML, every Attribute contains a string-value. This string-value needs to be converted into the value of the property-type the attribute represents. For primitive types like double, float, int, bool, char etc., the conversion automatically is done by the XAML-Parser (Silverlight and WinRT). Also for Properties of type enum, the XAML-Parser tries to convert the specified string-value into the enum-type of the property. There is also a conversion for some central types hardcoded in the XAML-Parser of Silverlight and WinRT, e.g. the Brush-Type. This conversion allows you to assign a string in XAML where a Brush-Instance is required:

<ListBox Background="Red">

The XAML-Parser takes the “Red”-string, creates a SolidColorBrush with the Color Red and assigns it to the Background-property of the ListBox.

(Excourse to WPF-XAML: In WPF-XAML this conversion is not done by the XAML-Parser, it is done by the BrushConverter-class)

Now if you have properties that are of your own type, let’s look at this works in Silverlight and WinRT. Let’s assume we have the classes below:

public class Person
{
  public Address Address { get; set; }
}
public class Address
{
  public string City { get; set; }
  public string Country { get; set; }
}

In Silverlight-XAML, it is possible to create a Person-instance as below if a TypeConverter for the Address-type exists:

<local:Person Address="Müllheim Germany"/>

The corresponding typeconverter could look like this:

public class AddressConverter : TypeConverter
{
  public override bool CanConvertFrom(...Type sourceType)
  {
    if (sourceType == typeof(string))
      return true;
    return base.CanConvertFrom(context, sourceType);
  }
  public override object ConvertFrom(...object value)
  {
    if (value != null && value is string)
    {
      var array = value.ToString().Split(' ');
      if (array.Length != 2)
        throw new ArgumentOutOfRangeException(
          "Invalid format for address");
      return new Address
      {
        City = array[0],
        Country = array[0]
      };
    }
    return base.ConvertFrom(value);
  }
}

The only thing that is additionally required is to tell the XAML-Parser where to find the AddressConverter. You do this by specifying the TypeConverterAttribute either on the Address-Property in the Person-class or on the Address-class itself. Below an example that specifies it on the Address-class.

public class Person
{
  public Address Address { get; set; }
}
[TypeConverter(typeof(AddressConverter))]
public class Address
{
  public string City { get; set; }
  public string Country { get; set; }
}

So far to Silverlight-XAML, now let’s look at WinRT-XAML. As mentioned above, WinRT-XAML also supports conversion for

  • primitive Types like bool, char, double, int, float,…
  • enumeration-values
  • central types like e.g. the Brush-type.

If you’ve custom types like the Address-class, currently there’s no support. There’s no TypeConverter in WinRT. Dot.

Markup-Extensions

In Silverlight-XAML it’s possible to create custom subclasses from MarkupExtension and use them in XAML with curly braces. WinRT doesn’t support custom Markup-Extensions. Dot.

Did you find out other bigger differences about XAML?

See you next week with the next post about WinRT and Windows Store-apps.

Thomas

Windows Store-apps with XAML and C# – blog series

Since yesterday evening Winodws 8 RTM is out for developers. This blogpost is the start of a blog-series about developing Windows Store-apps with XAML and C#. The series consists of some informational and some “how-to” posts:

More topics will come. If you’ve topics not listed above you want to read about, write a comment on this post.

The first post about XAML will be written till saturday evening

Thomas

Build applications for Windows 8

Yesterday morning Microsoft launched Windows 8 at the BUILD-conference in Anaheim. Windows 8 has a completely new tile- and touch-based UI with the Metro-Style we already know from Windows Phone 7.

For us as Developers the big question was how to develop applications for Windows 8. Microsoft already said something about HTML5 and JavaScript in another preview-video that appeared on youtube before. Yesterday they mentioned more about that topic. First of all:

All applications built for Windows 7 will still run on Windows 8.

Ok, know let’s look at the platform and the tools we’re using today with Windows.

plattformToolsToday

Today we’ve classical Applications running on the Desktop built with .NET, Silverlight or just a Win32-App. There are also Web-Applications built with HTML and Javascript running in Internet Explorer or another browser.

The problem Microsoft mentioned here is that these three things don’t work together very well. Therefore Microsoft reimagined the Windows-8-platform. You can use any language you wan’t to build the metro-style applications like the picture below shows.

plattformToolsWin8

As you can see in the picture above, Microsoft has also reimagined the Windows APIs. They know are calling the Windows APIs the Windows Runtime APIs, or short, the WinRT APIs. WinRT provides over 1800 objects for us developers to use. These 1800 objects are in four blocks:

  • Application Model
  • Communication & Data
  • Graphics & Media
  • Devices & Printing

It’s important to mention that all these blocks are natively built into Windows. It’s not a layer on top of windows, it is windows. The APIs are reflected in C/C++, C# and VB and also in Javascript. So you can use any language you want. Use C/C++/C# or VB and built your view in XAML, or use JavaScript and build your view in HTML/CSS

There’s Version 11 of Visual Studio that let’s you create the same Metro-style applications in the different languages.

visualStudio2011NewProject

Expression Blend 5 will beside XAML also support HTML. So there’s a great tooling for all view-languages.

Applications can be published in an App Store called the Windows Store. Same principle as Apple has with their App Store in Mac OS X Lion. Visual Studio 2011 therefore contains a new store-menu where you can upload a package directly from visual studio.

Go and grab a Windows 8 Preview with all the tools installed to get started developing Windows 8 apps here:

http://msdn.microsoft.com/en-us/windows/apps/br229516

Ok, the big question after knowing all of that is what happens to .NET, Silverlight, WPF in Windows 8? XAML stays, but Silverlight and WPF are just on the side, aren’t they? Let’s download the preview and discuss.