This commit is contained in:
sherlockforrest
2023-06-20 09:22:53 +08:00
commit bf2ed2e31f
621 changed files with 271599 additions and 0 deletions

34
WPF/AttachedProperty.md Normal file
View File

@@ -0,0 +1,34 @@
# 释义
本不属于某个对象的属性,在被需要的时候后来附加;在特定环境下对象才具有的属性如当一个控件在Grid中时会附加Grid.Column属性等
本质上是依赖属性
用clr属性包装时不同是采用两个方法
```csharp
public static int GetMyProperty(DependencyObject obj)
{
return (int)obj.GetValue(MyPropertyProperty);
}
public static void SetMyProperty(DependencyObject obj, int value)
{
obj.SetValue(MyPropertyProperty, value);
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.RegisterAttached("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));
```
把年级附加属性附加给人
```csharp
class Human:DependencyObject
{
}
Human human=new Human()
School.SetMyProperty(human,6)//设置属性
int grade=School.GetMyProperty(human)//得到属性值
```