是否很好地概述了各种XAML方言之间的差异

时间:2016-06-09 18:45:36

标签: wpf xaml silverlight win-universal-app uwp-xaml

在开发通用Windows应用程序(uwp)时,我经常需要查找如何在XAML中执行不同的操作。

一个问题是,我经常会遇到不适用于UWP应用的WPF或Silverlight或Windows Phone解决方案。各种方言之间是否存在差异?

如果没有,这可能是即将发布的stackoverflow文档功能的一部分。我非常愿意参与我已经知道的事情。

2 个答案:

答案 0 :(得分:4)

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)

答案 1 :(得分:0)

你好,不久之前,当我开始为UWP写作时,我找到了一篇真正帮助我的文章。看看here。此外,在StackOverflow here

中已经存在此问题