【问题标题】:Don't see a dependency property in the Designer在设计器中看不到依赖属性
【发布时间】:2012-04-03 19:10:08
【问题描述】:

我有一个 WPF MyUserControl。 在里面,我定义了一个依赖属性(默认情况下是 Visual Studio)

  Public Property Prop1 As String
    Get
      Return GetValue(Prop1Property).ToString()
    End Get

    Set(ByVal value As String)
      SetValue(Prop1Property, value)
    End Set
  End Property

  Public Shared ReadOnly Prop1Property As DependencyProperty = _
                      DependencyProperty.Register("Prop1", _
                      GetType(String), GetType(ctlMyUserControl.MyUserControl), _
                      New FrameworkPropertyMetadata(Nothing))

我成功编译了项目,但在 WPF 的控件设计器中没有看到我的Prop1。 为什么?

我还定义了一个“常用”属性,例如

Public Property Test1 As String

但我也没有在设计师身上看到它。为什么?

编辑

我在另一个 WPF 控件中添加了 MyUserControl,在那里我可以看到该属性。但是在 MyUserControl 本身的设计器中(当我选择根 UserControl 时),这些属性是不可见的......

【问题讨论】:

    标签: .net wpf dependency-properties designer


    【解决方案1】:

    我相信你必须装饰你的财产,例如:

    [Category("Configuration")]
    

    [Category("Configuration"), Browsable(true), Description("Title to show")]
    

    我认为当您在 userControl 的设计器中时看不到道具是正常的行为。您为什么要在那里看到它们,因为您只是“创建”用户控件,而不是使用它。

    【讨论】:

    • 奇怪的是,我可以在其他控件的设计器中看到它(如果我在那里添加 MyControl),但在 UserControl 的设计器本身中却看不到。
    • 我相信这实际上很正常 :D 当你创建/设计你的 userControl 时你不需要看到它们。当你消费它时,你只需要它们。
    猜你喜欢
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    • 2011-05-12
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多