XAML clr-namespace - 使用不兼容? [英] XAML clr-namespace - using incompatibility?

查看:26
本文介绍了XAML clr-namespace - 使用不兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WinRT 和 WP8 之间共享代码时:

When sharing code between WinRT and WP8:

WP8 想要:

xmlns:vm="clr-namespace:MyApp.ViewModels" 

WinRT 想要:

xmlns:vm="using:MyApp.ViewModels" 

这意味着您无法像在 WP7、Silverlight、WPF 中那样在项目之间共享 XAML 代码(如用户控件)

This means you can't share XAML code - like user controls - between projects the way we could in WP7, Silverlight, WPF

有没有人找到解决方法?XmlnsDefinition 属性看起来可以解决此问题,但 MS 将其从 WinRT 中移除.

Has anyone found a work-around ? XmlnsDefinition attribute looked like it might fix this, but MS took it out of WinRT.

推荐答案

此问题以及有限的解决方法在此处详细说明:http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714088(v=vs.105).aspx

This issue, along with the limited workarounds, is explained in detail here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714088(v=vs.105).aspx

  • Windows Phone 8 上的 XAML 和 Windows 8 上的 XAML 不是二进制兼容的.如前所述,用于构建 UI 的控件在每个平台上都是相似的.它们在名称、行为和它们公开的编程接口或语法.然而,他们是专门针对每个平台实施.
  • Windows Phone 8 的 XAML 和 Windows 8 的 XAML 中的命名空间前缀是不同的.这可以通过查看命名空间来说明从头开始创建时包含在基本页面中.[...]比较这些命名空间导入,您可以看到微妙但命名空间导入方式的显着差异.在 Windows 中电话 8,导入的命名空间以 clr-namespace: 为前缀.在Windows 8 导入的命名空间以 using: 为前缀.这使它很难使用相同的 XAML,除非您可以使用相同的语法.
  • XAML 不支持条件编译.作为在带有预处理器指令的条件编译中显示,条件编译是处理平台的有用技术通过在针对特定目标的代码路径中进行编译来区分平台,以及为另一个平台编译时的另一个代码路径.这使得在两个平台之间共享 XAML 页面变得困难,因为你不能简单地有条件地解决之前的问题在使用 clr-namespace for Windows 的命名空间导入中编译Phone 8 和使用:适用于 Windows 8.

这不应被视为共享之间的完整障碍Windows Phone 8 和 Windows 8.明确的指导是设计和为每个平台分别构建您的 UI,拥抱设计每个的指导方针.在技​​术上可以绕过这些障碍.您可以在页面初始化期间从代码.您可以在运行时从资源加载特定于平台的 XAML并将其作为字符串注入页面.然而,这些都没有技术可以扩展,它们可以构建您的核心资产——如何您的应用着眼于您的用户——这是一项繁琐且容易出错的任务.你的代码分享投资会给你带来更大的回报您的应用程序堆栈,通过尝试共享应用程序逻辑、数据模型、视图模型,等

This shouldn’t be seen as a complete roadblock for sharing between Windows Phone 8 and Windows 8. The clear guidance is to design and build your UI separately for each platform, embracing the design guidelines for each. It is technically possible to circumvent these obstacles. You could create your UI during page initialization from code. You could load platform-specific XAML from resources at runtime and inject it as a string into the page. However, none of these techniques scale and they make the construction of your core asset—how your app looks to your user—a tedious and error-prone task. Your code sharing investment will give you a much larger return further down your app stack, by trying to share app logic, data models, viewmodels, etc.

[...] 一种在某些情况下可以使用的共享 UI 的技术是将部分 UI 隔离到用户控件中并尝试共享那些.[...] 但是,由于在本次讨论的开始,该技术仅限于基本用户控件.除了这些限制之外,您还应该考虑始终构建适合目标的用户体验的指南平台.共享 XAML 控件是可能的,但受到限制.一个好的这种共享的候选对象是您想要在您想要共享的弹出窗口或其他小部件,因为它们通常由基本 UI 元素组成,没有复杂的 XAML和简单的造型.

[...] One technique for sharing UI that can be of use in some circumstances is to isolate parts of your UI into user controls and attempt to share those. [...] However, due to the limitations called out at the beginning of this discussion, the technique is limited to basic user controls. In addition to those limitations, you should consider the guideline to always build your user experience to suit the target platform. Sharing XAML controls is possible but limited. A good candidate for this kind of sharing is UI you want to display in a pop-up window or other widgets that you want to share because they typically will be composed of basic UI elements with no complex XAML and with simple styling.

这篇关于XAML clr-namespace - 使用不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆