c# - Visual Studio 2019 设计器,在设计器中设置数组属性会导致弹出“属性值无效”
问题描述
我正在使用 Visual Studio 2019 版本 16.8.2 我有一个 .net Core 5 用户库。为了诊断转换为 Core 5 的现有项目中的问题,我创建了一个简单的用户控件:
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace WinFormsControlLibrary2
{
public partial class UserControl1 : UserControl
{
private TwoElems[] mynums = { new TwoElems(), new TwoElems() };
public UserControl1()
{
InitializeComponent();
}
[Browsable(true), NotifyParentProperty(true), EditorBrowsable(EditorBrowsableState.Always)]
[Category("Log control parameters")]
[DisplayName("array property")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TwoElems[] MyNums
{
get { return mynums; }
set { mynums = value; }
}
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class TwoElems
{
[Browsable(true), NotifyParentProperty(true), EditorBrowsable(EditorBrowsableState.Always)]
public int sz { get; set; }
public TwoElems()
{
sz = 30;
}
}
}
这编译得很好,并且包含此用户控件的项目被添加到工具箱中。然后将控件添加到窗体中,单击省略号 (...) 打开 MyNums 的子属性页面,显示项目。
更改任一项目的值会导致属性表中的弹出窗口显示:属性值无效并且详细信息为:对象引用未设置为对象的实例。
单击确定关闭弹出窗口并重新检查数组属性显示更改的值已写回属性。
这种代码(数组属性)在 .net 框架和/或更早版本的 Visual Studio 下运行良好。
关于如何确定是什么原因造成的任何想法?
问候,奥兹
解决方案
推荐阅读
- django - Django 向 API 发送请求,其中 URL 是动态的
- amazon-web-services - 基于标签限制 EC2 访问的 IAM 策略
- webforms - 在 Web 表单附件 URL 中添加令牌值
- javascript - 对字符串进行计数的另一种方法出现在数组中
- javascript - Javascript:在“onkeyup”事件中仅屏蔽信用卡号的前 12 位数字
- ubuntu-18.04 - 口径未在 ubuntu 18.04.03 LTS 下启动
- php - 如何在代码嗅探器中查找和更改规则集?
- c# - 无法理解 MVP Winforms C# 中的被动视图
- java - JPA Hibernate 映射视图 - 查询随机抛出错误
- javascript - 使引导警报出现并可堆叠