【问题标题】:Common base class or interface for StackPanel and ControlStackPanel 和 Control 的通用基类或接口
【发布时间】:2011-09-21 20:32:48
【问题描述】:

我需要一个函数来返回可以是 System.Windows.Controls.Control 或 System.Windows.Controls.StackPanel 的东西。

理想情况下,它应该是由两者实现的接口或两者的基类(我讨厌为此目的使用对象)

UIElement 等之类的东西似乎只属于其中一个。

有什么想法吗?

【问题讨论】:

    标签: wpf silverlight controls stackpanel base-class


    【解决方案1】:

    FrameworkElement 看起来是你唯一的选择。

    【讨论】:

      【解决方案2】:

      FrameworkElement 是最接近两者的祖先,但任何高于它的都可以(包括 UIElement):

      System.Object 
        System.Windows.Threading.DispatcherObject
          System.Windows.DependencyObject
            System.Windows.Media.Visual
              System.Windows.UIElement
                System.Windows.FrameworkElement
                  System.Windows.Controls.Panel
                    System.Windows.Controls.StackPanel
      
      System.Object 
        System.Windows.Threading.DispatcherObject
          System.Windows.DependencyObject
            System.Windows.Media.Visual
              System.Windows.UIElement
                System.Windows.FrameworkElement
                  System.Windows.Controls.Control
      

      【讨论】:

      • 感谢这项工作。我更喜欢框架元素,因为它是最接近的祖先,并且提供其他开发人员将其用于非预期目的的可能性最小。
      猜你喜欢
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      相关资源
      最近更新 更多