Convert WPF XAML to 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


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

链接地址: http://www.djcxy.com/p/5890.html

上一篇: System.Windows.Ria.Controls和POCO

下一篇: 将WPF XAML转换为Silverlight XAML