如何在WPF设计器中自定义XAML序列化 [英] how to customize XAML serialization in WPF designer

查看:208
本文介绍了如何在WPF设计器中自定义XAML序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我为Visual Studio WPF设计器实现了一个自定义属性值编辑器,并遇到了一个问题。我的属性编辑器编辑了我的自定义属性类型(比如  PropertyType) 它可以转换为字符串和从字符串转换。属性编辑器在DialogPropertyValueEditor类的ShowDialog方法中获取并设置
代码中属性的值。


所以我有一个带有自定义控件的xaml文件,这个控件有PropertyType的属性。此属性的值在XAML文件中指定为字符串表示形式中的属性。我选择此控件,转到"属性"窗口并使用我的自定义属性编辑器编辑
此属性。一切都还可以,直到这一刻,属性值从string属性成功解析并传递给我的属性编辑器。但是当我在DialogPropertyValueEditor.ShowDialog,
中设置修改后的属性值时,WPF设计器会将此值序列化为XAML作为属性元素。它忽略了字符串转换的可能性,并在序列化时丢失了一些重要数据。我尝试在我的PropertyType类上引入TypeConverter属性,使用System.ComponentModel.Design.Serialization
命名空间类,但没有任何作用。


问题是如何才能获得WPF设计器使用我的自定义字符串序列化将我的属性序列化为属性?


 

解决方案

< p style ="margin:0in 0in 0pt"> 嗨@Kiryushin Andrey



我已经与我们的开发团队进行了交谈,我们认为您应该能够使用类型转换器将该属性序列化为
to一个字符串。 



这将有助于我们查看代码示例&您想要发出的XAML - 如果您不愿意公开发布感觉
可以免费给我发送电子邮件到mwthomas at microsoft dot com。



谢谢


Mark


Hi to all!

I have implemented a custom property value editor for Visual Studio WPF designer and stuck into one problem. My property editor edits my custom property type (say PropertyType) which is convertable to and from string. Property editor gets and sets the property's value in code, in ShowDialog method of DialogPropertyValueEditor class.

So I have a xaml file with my custom control in it, and this control has a property of PropertyType. The value of this property is specified in XAML file as an attribute in a string representation. I select this control, go to the Properties window and edit this property with my custom property editor. Everything is OK till this moment, the property value is parsed successfully from the string attribute and passed to my property editor. But when I set the modified property's value in DialogPropertyValueEditor.ShowDialog, the WPF designer serializes this value to XAML as property element. It ignores the possibility of string conversion and loses some important data when serializing. I have tried introducing TypeConverter attribute on my PropertyType class, playing with System.ComponentModel.Design.Serialization namespace classes, but nothing works.

The question is how can I get the WPF designer to serialize my property to attribute, using my custom string serialization?

 

解决方案

Hi @Kiryushin Andrey

I have spoken to one of our development team, and we think you should be able to use type converters to serialize the property back to a string. 

It would help us to see a sample of the code & desired XAML you are trying to emit - if you would rather not post publicly feel free to drop me an email at mwthomas at microsoft dot com.

Thanks

Mark


这篇关于如何在WPF设计器中自定义XAML序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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