【问题标题】:Nested property for user control用于用户控件的嵌套属性
【发布时间】:2014-04-22 11:42:42
【问题描述】:

我已经创建了用户控件并定义了所有属性。我能够在设计时访问/修改该属性。这里我需要知道如何将嵌套属性赋予同一个控件。

例如,考虑默认属性“Font”,它具有“Bold”、“Italic”、“Names”等子属性。像这样,我需要在我的自定义控件中嵌套属性。

实际上,我的 Web 应用程序中的用户控件需要像这样的嵌套属性。

提前致谢。

【问题讨论】:

    标签: c# asp.net properties user-controls


    【解决方案1】:

    尝试将所有属性更改为依赖属性。例如:

     public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(Choice));
         public string Text
         {
              get { return (string)GetValue(TextProperty); }
              set { SetValue(TextProperty, value); }
         }
    
         public static DependencyProperty Choice4Property = DependencyProperty.Register("Choice4", typeof(Choice), typeof(MyControl));
         public Choice Choice4
         {
              get { return (Choice)GetValue(Choice4Property); }
              set { SetValue(Choice4Property, value); }
         }
    

    【讨论】:

    • 感谢您的建议。请分享 SetValue 和 GetValue 方法定义的代码 sn-p。
    猜你喜欢
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多