在网络中传输XAML元素 [英] Transfer XAML Elements in Network

查看:57
本文介绍了在网络中传输XAML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过网络传输XAML元素(如椭圆或矩形).

我可以序列化它们,但是在转移和强制转换后,结果对象的属性为空.

为什么会这样呢?


服务器

I want to transfer my XAML-Elements (like Ellipses or Rectangles) over the Network.

I am able to Serialize them but after the transfer and the casting the attributes of my resulting object are empty.

Why this happens ?


Server

MemoryStream ms = new MemoryStream();
XamlWriter.Save(element, ms);
byte[] ele = ms.ToArray();
ms.Close();




客户端




Client

MemoryStream ellipse = new MemoryStream(ellipseBytes);
Ellipse myEli = (Ellipse)XamlServices.Load(ellipse);

推荐答案

原因不匹配:

要么同时使用XamLWriter和XamlReader,要么使用XamlSevices.Load和.Parse方法

请谨慎使用此处的外部参考.但是,只要使用简单的对象,它就会起作用.


在codeproject中检查此处[ ^ ]
http://msdn.microsoft.com/en -us/library/system.windows.markup.xamlreader(v = vs.100).aspx [ http://msdn.microsoft.com/zh-cn/library/system.xaml.xamlservices.parse%28v = VS.100%29.aspx [
The reason is a mismatch :

either use both XamLWriter and XamlReader or use XamlSevices.Load and .Parse methods

careful with external references here. But as long as you use simple objects, it will work.


Check here in codeproject[^]
http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader(v=vs.100).aspx[^]

also check the warning here:
http://msdn.microsoft.com/en-us/library/system.xaml.xamlservices.parse%28v=VS.100%29.aspx[^]


这篇关于在网络中传输XAML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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