15

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.

stefan.s
  • 3,489
  • 2
  • 30
  • 44
  • 2
    WP, and UWP are for the most part derived from Silverlight XAML. So most XAML solutions will either directly or easily port between those. WPF has some nuance differences with things like heavier usage of Triggers/Setters vs VisualStateManager and things like usage of x:Type and explicit Path. While Win Embedded also has some nuance stumpers since it's more based on Silverlight v2. Either way, with your rep you have to know this question is really broad brother. Though I'm curious also but have plans to make a blog thingy on the subject at some point too. Just no free time lately. :) – Chris W. Jun 09 '16 at 19:09
  • 1
    @ChrisW. I would really hope. that the community could tackle this in the new documentation part of stackoverflow. That would be very beneficial. – stefan.s Jun 10 '16 at 04:51
  • 1
    Maybe if we asked someone like @JerryNixon really, really nicely he might help out in that regard. It would take some time to sift through and construct such a document unless it was just hitting the bare basics, but I agree it would likely help a lot of folks out. Just so little time available for some of us lol. Guess I'll throw this one in the favorites list also. – Chris W. Jun 10 '16 at 13:54

2 Answers2

7

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)

CL.
  • 173,858
  • 17
  • 217
  • 259
stefan.s
  • 3,489
  • 2
  • 30
  • 44
0

Hello sometime ago when I was starting to write for UWP I found an article that really helped me. Take a look here. Also There was already a question about this in StackOverflow here

Community
  • 1
  • 1
Hasan Hasanov
  • 1,129
  • 2
  • 15
  • 23