从 XAML 加载元素
我有一个像这样的自定义 XAML 用户控件:
<UserControl x:Class="CheckPoint.Modules.Beach.Beach_Shape"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Polygon Name="Shape"></Polygon>
</Grid>
</UserControl>
我希望使用 XamlWrite.Save 对其进行 xaml 序列化,然后使用 XamlReader.Load 重新加载它。
XmlReader reader = XmlReader.Create(new StringReader(xml));
UserControl uc=(UserControl)XamlReader.Load(reader);
myGrid.Children.Add(uc);
“uc”在 myGrid 上正确可视化,但“uc”对象在逻辑上不正确,因为 Shape 元素未正确加载,例如它没有设置背景、描边或点,即使它位于 xaml 中。
我尝试重新加载它,
Shape=myGrid.Findname("Shape");
但它也不起作用。
那么,我的错误在哪里呢?
I have a custom XAML User Control like this:
<UserControl x:Class="CheckPoint.Modules.Beach.Beach_Shape"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Polygon Name="Shape"></Polygon>
</Grid>
</UserControl>
I want xaml serialize it with XamlWrite.Save and then reload it with XamlReader.Load.
XmlReader reader = XmlReader.Create(new StringReader(xml));
UserControl uc=(UserControl)XamlReader.Load(reader);
myGrid.Children.Add(uc);
"uc" is correctly visualized on myGrid, but "uc" Object is not logical correct, becouse the Shape element is not correctly loaded, for example it has not Background, Stroke or Points setted even though it are in xaml.
I try to reload it with
Shape=myGrid.Findname("Shape");
but it doesn't work too.
So, where is my mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是您问题的答案(来自 MSDN 文章 XamlWriter.Save 的序列化限制< /a>):
This might be an answer for your question (from MSDN article Serialization Limitations of XamlWriter.Save):