VS2010 中的 winUserControl - 属性在设计器中不可见

发布于 2024-11-30 03:20:28 字数 1323 浏览 1 评论 0原文

我的 Visual Studio 2010 Express 环境有一个问题:当我设计自己的 UserControl 时,在属性网格中我看不到该控件的公共属性。然而,它们在引用此控件的项目中是可见的。
由于它是 Express 版本,我创建新的空项目,然后向其中添加新的 UserControl。
然后,为了进行测试,我放置了以下代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project1
{
    public partial class UserControl1 : UserControl
    {
        private int myNumber;

        [Browsable(true)]
        public int MyNumber
        {
            get
            {
                return myNumber;
            }
            set
            {
                myNumber = value;
            }
        }


        public UserControl1()
        {
            InitializeComponent();
        }
    }
}  

在 VS 2008 中,我记得,即使没有 [Browsable(true)] 属性,也应该足以在属性网格中显示 MyNumber 属性。然而,在 VS 2010 中,当我在解决方案资源管理器中双击 UserControl1.cs 并查看“属性”时,我看不到 MyNumber。
当我在另一个项目中引用和使用此控件时,可以访问它的属性。

我尝试完全重新安装VS 2010环境,包括SP1,但没有成功。您知道可能出了什么问题吗?

顺便说一句:这些属性都不起作用:

[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Bindable(true)]

最好的问候,
马尔钦

I have a problem with (I suppose) my Visual Studio 2010 Express environment: when I design my own UserControl, in Properties grid I can't see public properties of that control. They are however visible in the project, that reference this control.
As it's Express Edition, I create new empty project, then add new UserControl to it.
Then, for a test, I put following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project1
{
    public partial class UserControl1 : UserControl
    {
        private int myNumber;

        [Browsable(true)]
        public int MyNumber
        {
            get
            {
                return myNumber;
            }
            set
            {
                myNumber = value;
            }
        }


        public UserControl1()
        {
            InitializeComponent();
        }
    }
}  

In VS 2008, as I remember, that should be enogh to show MyNumber property in Properties grid, even without [Browsable(true)] attribute. In VS 2010 however, when I double click UserControl1.cs in Solution Explorer and look in Properties, I don't see MyNumber.
When I reference and use this control in another project, there is an access to it's properties.

I've tried to competly reinstall VS 2010 environment, including SP1, but with no success. Do you have any idea what can be wrong?

By the way: none of these attributes are working, either:

[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Bindable(true)]

Best regards,
Marcin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

百善笑为先 2024-12-07 03:20:28

我相信这是 VS2010 的正常行为,并假设这是设计使然。对于我来说,2010 Ultimate 的表现是一样的。当您将 UserControl1 放置在表单上时,您将看到其自定义属性。

我的猜测是,这是因为当您设计控件时,还没有控件的实例(它甚至可能尚未编译)。您看到的是UserControl 的一个实例。当您编译控件并将其添加到窗体时,设计器将创建控件的实例,以便可以查看和操作其属性。

I believe this the normal behavior of VS2010 and assume it's by design. It behaves the same for me in 2010 Ultimate. When you place UserControl1 on a form, you'll see its custom properties.

My guess is this is because when you're designing the control, there is no instance of your control yet (it may not have even been compiled). What you're looking at is an instance of UserControl. When you compile your control and then add it to a form, the designer creates an instance of your control, so its properties can be seen and manipulated.

不气馁 2024-12-07 03:20:28

我以前没有使用过 [Browsable] 标签。然而,下面是我在我的一个项目中使用的示例。

[Description("The length used to display the dimensions")]
[Category("Custom")]
public double DisplayLength { get; set; }

我猜你需要添加一个类别。

I haven't used the [Browsable] tag before. However below is an example of what I'm using in one of my projects.

[Description("The length used to display the dimensions")]
[Category("Custom")]
public double DisplayLength { get; set; }

I'm guessing you need to add a category.

走野 2024-12-07 03:20:28

由于 VS 在 Designer 中处理 ascx 的方式,这将不起作用。有关详细信息,请参阅这个优秀的回答 SO。

如果答案不是您所期望的,您仍然可以将 .ascx'es 迁移到用户控件库,如我在 我的博客

如果可以选择,我会将所有 ascx 代码重新设置为 自定义 Web 服务器控件

This won't work due to the way VS handles ascx'es in Designer. For details, see this excellent answer on SO.

If the answer is not what you expected, you can still migrate the .ascx'es to a User Control library as I described in my blog.

If I had the choice, I would start over all my ascx code as Custom Web Server Controls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文