C# class中的attribute和property
Microsoft的C#帮助文档中的class包含两个信息。attribute property,中文版均翻译成“属性”。这里严重混淆了2个重要概念。property就是属性,可以通过get,set来访问。和class中另一个概念field“字段”的区别比较明显。
而attribute又代表了什么呢,attribute其实反映了一种继承关系,也就是说该class具有什么样的接口。attribute反应了一种归属,可理解为特征。
- attribute确定了该对象的type。1个对象可以有多个不同的attribute,不同的对象也可以有相同的attribute。
- 在使用某个attribute的接口时,不同的拥有该attribute的class对象可以相互替换。
- 对象的class和type是不同的,class是property的集合,可以理解为物理特性。而type是attribute的集合,可以理解为功能属性。
- 张三是个男人(class),(能打枪(attribute),能开炮(attribute),能开车(attribute))type。
李四是个女人(class),(能打枪(attribute))type。
那么在执行打枪任务的时候,张三和李四是可以相互替换的,这样就增加了灵活性。
Panel 类
定义
命名空间:
System.Windows.Controls
程序集:
PresentationFramework.dll
为所有 Panel 元素提供基类。 使用 Panel 元素放置和排列 Windows Presentation Foundation (WPF) 应用程序中的子对象。
。。。。。
继承
Object
DispatcherObject
DependencyObject
Visual
UIElement
FrameworkElement
Panel
派生
System.Windows.Controls.Canvas
System.Windows.Controls.DockPanel
System.Windows.Controls.Grid
System.Windows.Controls.Primitives.TabPanel
System.Windows.Controls.Primitives.ToolBarOverflowPanel
更多…
属性(这里是attribute)
LocalizabilityAttribute ContentPropertyAttribute
实现
IAddChild
构造函数
Panel()
初始化 Panel 类的新实例。
字段
BackgroundProperty
标识 Background 依赖项属性。
IsItemsHostProperty
标识 IsItemsHost 依赖项属性。
ZIndexProperty
标识 ZIndex 附加属性。
****属性这里是property
ActualHeight
获取此元素的呈现高度。
(继承自 FrameworkElement)