我有一个这样的自定义 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>
我希望 xaml 使用 XamlWrite.Save 对其进行序列化,然后使用 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");
但它也不起作用。
那么,我的错误在哪里?