作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何在 VS 属性窗口(可折叠的多属性)中制作这样的东西:
我试过这样的代码:
Test z = new Test();
[ Browsable(true)]
public Test _TEST_ {
get { return z; }
set { z = value; }
}
[Browsable(true)]
public class Test {
[Browsable(true)]
public string A { get;set; }
[Browsable(true)]
public string B { get;set; }
}
最佳答案
好的,我有一些工作可以满足您的情况。
要在 PropertyGrid 中扩展一个类,您必须添加 TypeConverterAttribute
到它,引用 ExpandableObjectConverter
的类型(或从它派生的其他东西)。
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Test
{
[Browsable(true)]
public string A { get; set; }
[Browsable(true)]
public string B { get; set; }
}
ToString()
方法的返回值作为您的类的值)。你可以忍受它(你可能不想),改变
ToString()
返回值更合适的东西或使用自定义
TypeConverter
对于这种情况。
internal class TestConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
return "";
return base.ConvertTo(context, culture, value, destinationType);
}
}
[TypeConverter(typeof(TestConverter))]
public class Test
{
[Browsable(true)]
public string A { get; set; }
[Browsable(true)]
public string B { get; set; }
}
Point
的对象。用
[10,5]
可视化当
X
是
10
和
Y
是
5
.当您输入新值时,它们会被解析并设置为原始字符串引用的整数。
关于c# - 如何在 .NET/Visual Studio 中创建可浏览的类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60496208/
我是一名优秀的程序员,十分优秀!