c# - 如何删除 PropertyGrid 中的默认显示字符串“(集合)”?
问题描述
我的目标是通过自己的 UITypeEditor 替换 PropertyGrid 属性的显示值。但我无法删除始终显示的默认显示字符串“(集合)”。
我尝试了 e.Graphics.Clear 并用白色画笔在图形中绘图。但这行不通。这是我的代码:
public class MyUITypeEditor : UITypeEditor
{
public override void PaintValue(PaintValueEventArgs e)
{
// Not working:
//e.Graphics.Clear(Color.White);
//using (SolidBrush brush = new SolidBrush(Color.White))
//{
// e.Graphics.FillRectangle(brush, e.Bounds);
//}
e.Graphics.DrawString(
"0|0, 10|10",
new Font("Arial", 10f, FontStyle.Bold),
new SolidBrush(Color.Black),
new Point(0, 0));
}
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
}
解决方案
您要做的是定义一个新TypeConverter
元素并覆盖以下方法:
public class test_typeconverter : TypeConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
object value, Type destinationType)
=> "Text requiered";
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => true;
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => false;
}
然后,您必须将此类型定义为要在属性网格中显示的集合的类型转换器,如下所示:
[TypeConverter(typeof(test_typeconverter))]
public List<int> Values { get; set; }
推荐阅读
- ethereum - 如何在solidity中解决此错误“如果您发送值,则应支付构造函数。”?
- woocommerce - Woocommerce 在目录/商店页面上显示变体缩略图
- c# - 如何检测图像何时出现在 PictureBox 中
- python - 从“deeppavlov.core.commands.train”导入“train model from_config”时出错
- python - 使用 Flask 返回 Html 属性
- ruby-on-rails - 如何使用下拉列表从独立页面设置 id?或者我如何保存belongs_to、has_many 值?
- javascript - 如何在 vue.js 组件中使用导入的 javascript 库构造函数?
- android - 在 ScrollView 中使用可扩展的 textView 垂直居中 ConstraintLayout(滚动/居中问题)
- android - 在 Firebase Android 中读写
- r - 基于R中多个其他变量中的值有条件地替换变量中的值