WPF - 克隆数据绑定对象?
我正在尝试使用如下代码克隆 WPF 绑定对象(列表框)
pgeIncidentReport newPage = new pgeIncidentReport();
newPage.SetReportData();
string listXaml = XamlWriter.Save(newPage.lstUsers);
但是,当您查看 listXaml 字符串时,我注意到列表本身和 DataTemplate 的数据绑定指令都是空白且不再存在。是否有理由将其删除?是否有另一种方法来克隆将保留所有设置的对象?
I am trying to clone a WPF bound object (a listbox) with code like the following
pgeIncidentReport newPage = new pgeIncidentReport();
newPage.SetReportData();
string listXaml = XamlWriter.Save(newPage.lstUsers);
However, when you view the listXaml string, I noticed that my databinding directives, for both the list itself and the DataTemplate are blank and no longer there. Is there a reason why that is being removed? Is there another way to clone objects that will maintain all of the settings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不想回答我自己的问题,但我通过使用此类找到了答案: http:// /www.codeproject.com/KB/WPF/XamlSerializer.aspx
本文也有一定程度的帮助,但第一篇文章中的解决方案更容易实现: codeproject.com/KB/WPF/xamlwriterandbinding.aspx?fid=1428301&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2801571" rel="nofollow noreferrer">http:// /www.codeproject.com/KB/WPF/xamlwriterandbinding.aspx?fid=1428301&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2801571
Hate to answer my own question, but I found the answer by using this class: http://www.codeproject.com/KB/WPF/XamlSerializer.aspx
This article also helped to a certain degree but the solution in the first article is much easier to implement: http://www.codeproject.com/KB/WPF/xamlwriterandbinding.aspx?fid=1428301&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2801571