将 WPF XAML 转换为 Silverlight XAML

发布于 2024-08-14 00:24:40 字数 1355 浏览 5 评论 0原文

我对跨 WPF 和 Silverlight 平台使用 XAML 有疑问。

背景:

我有一个 silverlight 应用程序,需要将 Xaml 传递到 WPF 并进行一些计算来更新 XAML。当我在 WPF 中运行更改时,我解析 XAML 并将其转换为 Canvas 对象,该对象完美地完成了工作。问题是 WPF 删除了 silverlight 命名空间,甚至删除了一些元素的名称。

我用来将 XAML 转换为 Canvas 的代码

Canvas canvas = XamlReader.Parse(xaml) as Canvas

下面是 Silverlight 的原始 Xaml:

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Holder" Width="58" Height="23" >

.......

将其转换为 Canvas 对象后,Canvas 的 Xaml 变为:

<Canvas Name="Holder" Width="58" Height="23" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Canvas.Clip><RectangleGeometry RadiusX="0" RadiusY="0" Rect="0,0,58,23"/>
</Canvas.Clip><Rectangle Name="HolderBackground" Canvas.Top="0.4" Canvas.Left="0.4" Width="57.2" Height="22.2" RadiusX="0" RadiusY="0" Fill="#FFFFFF" />
<Canvas Name="Image1" Canvas.Top="0.8" Canvas.Left="0.8" Width="24.37999153137207" Height="21.4"> .......

您应该注意到 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 是丢失的。此外,所有 x:Name 现在都变为 Name。如果您仔细观察,您会发现该元素的名称已被删除

大家是否有任何想法或简单的解决方案,我可以将 Silverlight XAML 转换为&gt; WPF XAML ->(返回)Silverlight XAML?

干杯

I have question about using XAML across the WPF and Silverlight platforms.

Background:

I have a silverlight app that needs to pass the Xaml to WPF and do some calculation to update the XAML. When I run the changes in WPF, I parse the XAML and convert it to the Canvas object which does the job perfectly fine. The problem is WPF strip out the silverlight namespace and even delete the name of some elements.

The code that I use to convert XAML into Canvas

Canvas canvas = XamlReader.Parse(xaml) as Canvas

Here is the original Xaml from Silverlight:

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Holder" Width="58" Height="23" >

.......

After I convert it to a Canvas object, the Xaml of the Canvas become this:

<Canvas Name="Holder" Width="58" Height="23" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Canvas.Clip><RectangleGeometry RadiusX="0" RadiusY="0" Rect="0,0,58,23"/>
</Canvas.Clip><Rectangle Name="HolderBackground" Canvas.Top="0.4" Canvas.Left="0.4" Width="57.2" Height="22.2" RadiusX="0" RadiusY="0" Fill="#FFFFFF" />
<Canvas Name="Image1" Canvas.Top="0.8" Canvas.Left="0.8" Width="24.37999153137207" Height="21.4"> .......

You should notice the xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" is missing. Also, all the x:Name now becomes Name. If you look closely, you will notice this element's name has been removed

Does everyone have any idea or simple solution that I can convert Silverlight XAML -> WPF XAML ->(back to) Silverlight XAML?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2024-08-21 00:24:40

看起来我必须自己回答这个问题,但这不是一个明确的答案,

有人编写了一个自定义 XamlWriter 类来解决部分问题,但 RectangleGeometry 问题的缺失名称仍然存在
http://social. msdn.microsoft.com/Forums/en-US/wpf/thread/08aebbf1-0a61-4305-83b2-a0a37bb24002

It looks like I have to self-answer this, but it's not a defn answer

someone wrote a custom XamlWriter class that resolves part of the problem, but the missing name of RectangleGeometry problem would still exist
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/08aebbf1-0a61-4305-83b2-a0a37bb24002

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文