Friday, August 28, 2015

Okra App Framework for Windows 10 Universal

[Cross posted from the official Okra App Framework blog]

Okra App Framework v1.2

With the release of Windows 10, Microsoft have introduced the Universal Windows Platform with a single API set and one app package to target PCs, tablets, phones and more. Today’s release of version 1.2 of the Okra App Framework allows you to write apps that target Windows 10 devices.

New in version 1.2 is,

  • Windows 10 UAP support - Use the MVVM pattern to write a single app that runs on PCs, tablets and phones running Windows 10.
  • Windows 10 UAP Visual Studio Template - A basic Visual Studio template is available to get you started with developing Windows 10 apps.
  • Advanced Windows 10 features include,
    • Compiled binding support (see below)
    • Automatic support for hardware back buttons and tablet mode

You can get the Okra App Framework now by installing the Visual Studio extension, from NuGet or via GitHub. Full details on how to download the framework are available here.

Windows 10 Compiled Binding Support

Since the MVVM pattern relies heavily on data binding to bind the UI to the underlying view-model, data binding performance is very important. The Universal Windows Platform introduces “compiled binding” as a high performance data binding system.

To use compiled bindings you use the new x:Bind syntax,

<TextBlock Text="{x:Bind ViewModel.Title}"/>

Note however that these bindings do not bind to the DataContext, but instead to the page itself. To support this, the Okra App Framework v1.2 introduces the IViewModelBindable interface. This is applied to the page code-behind as shown below,

public sealed partial class MyPage : Page, IViewModelBindable
{
    ...

    public HomeViewModel ViewModel
    {
        get;
        private set;
    }

    public void SetViewModel(object viewModel)
    {
        this.ViewModel = viewModel as HomeViewModel;
        Bindings.Update();
    }
}

You can now take advantage of type-safe, high performance data binding using the x:Bind syntax in your Windows 10 projects.