Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good overview of the differences between the various XAML dialects

While developing a universal windows app (uwp) I frequently need to look up how to do different things in XAML.

One problem is, that all too often I end up with a solution for WPF or Silverlight or Windows Phone which is not applicable to an UWP app. Is there a good overview with differences between the various dialects?

If not, could this be something which is a part of the upcoming stackoverflow documentation feature. I'm very willing to participate with the things I'm already aware of.

like image 641
stefan.s Avatar asked Jun 09 '16 18:06

stefan.s


People also ask

Is XAML a programming language?

XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next-generation managed applications. XAML is the language to build user interfaces for Windows and Mobile applications that use Windows Presentation Foundation (WPF), UWP, and Xamarin Forms.

Why do we use XAML in WPF?

The goal of XAML is to enable visual designers to create user interface elements directly. WPF aims to make it possible to control all visual aspects of the user interface from mark-up.

What is core XAML?

XAML is a declarative markup language. As applied to the . NET Core programming model, XAML simplifies creating a UI for a . NET Core app.


1 Answers

Compiled data bindings: The {x:Bind} markup extension

Databings are essential for working with XAML. The XAML dialect for UWP apps provides a type of binding: the {x:Bind} markup extension.

Working with {Binding XXX} and {x:Bind XXX} is mostly equivalent, with the difference that the x:Bind extension works at compile time, which enables better debugging capabilities (e.g. break points) and better performance.

<object property="{x:Bind bindingPath}" />

The x:Bind markup extension is only available for UWP apps. Learn more about this in this MSDN article: https://msdn.microsoft.com/en-us/windows/uwp/data-binding/data-binding-in-depth.

Alternatives for Silverlight, WPF, Windows RT: Use the standard {Binding XXX} syntax:

<object property="{Binding bindingPath}" />

Importing namespaces in XAML

Most of the time you need to import namespaces in your XAML file. How this is done is different for the different XAML variants.

For Windows Phone, Silverlight, WPF use the clr-namespace syntax:

<Window ... xmlns:internal="clr-namespace:rootnamespace.namespace"
            xmlns:external="clr-namespace:rootnamespace.namespace;assembly=externalAssembly"
>

Windows RT, UWP use the using syntax:

<Page ... xmlns:internal="using:rootnamespace.namespace"
          xmlns:external="using:rootnamespace.namespace;assembly=externalAssembly"
>

Multi Binding

Multi Binding is a feature exclusive for WPF development. It allows a binding to multiple values at once (typically used with a MultiValueConverter).

<TextBox>
    <TextBox.Text>
        <MultiBinding Converter="{StaticResource MyConverter}">
            <Binding Path="PropertyOne"/>
            <Binding Path="PropertyTwo"/>
        </MultiBinding>
    </TextBox.Text>
</TextBox>

Platforms other than WPF don't support multi binding. You have to find alternative solutions (like moving the code from view and converters to the viewmodel) or resort 3rd party behaviours like in this article: http://www.damirscorner.com/blog/posts/20160221-MultibindingInUniversalWindowsApps.html)

like image 81
stefan.s Avatar answered Sep 26 '22 23:09

stefan.s