【发布时间】:2018-01-07 13:39:37
【问题描述】:
我在画布中动态创建了控件,当我序列化 Canvas 事件时,没有序列化。
Label label = new Label();
...
label.MouseLeftButtonDown += Control_MouseLeftButtonDown;
label.MouseLeftButtonUp += Control_MouseLeftButtonUp;
label.MouseMove += Control_MouseMove;
label.MouseLeave += Control_MouseLeave;
...
public static string SerializeXAML(UIElement element)
{
string strXAML = System.Windows.Markup.XamlWriter.Save(element);
return strXAML;
}
public static UIElement DeserializeXAML(string XAML)
{
return System.Windows.Markup.XamlReader.Parse(XAML) as UIElement;
}
序列化字符串:
<Canvas Background="#FFFFFFFF" Name="DesignCanvas" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Label FontSize="12" Focusable="True" Canvas.Left="363.146190476191" Canvas.Top="179.774339118825" Panel.ZIndex="2">Label</Label></Canvas>
我要<Label ... MouseLeftButtonDown="Control_MouseLeftButtonDown">text</Label>
有可能吗? 谢谢
【问题讨论】:
标签: c# wpf xaml serialization