简体   繁体   English

依赖项属性-存储,Grid.Row

[英]Dependency property - storage, Grid.Row

I'm trying to understand WPF in details. 我试图详细了解WPF。 So far I don't know how work 2 things: 到目前为止,我不知道如何工作两件事:

1.Where Dependency Property (DP) is stored? 1. Dependency Property(DP)存储在哪里?

My guesses: DP is static, so this object (DP) is same for all objects that are derived from class, that have this DP. 我的猜测:DP是静态的,因此此对象(DP)对于从类派生且具有此DP的所有对象都是相同的。 I suppose that DP has its own storage, where DP saves values for all objects that use this DP. 我想DP具有自己的存储,其中DP保存使用该DP的所有对象的值。 Mb sth like dictionary... Mb像字典一样...

2.How the Grid can assign an object (for example Button) to its own row (in details)? 2.网格如何将对象(例如Button)分配给自己的行(详细信息)?

My guesses: 我的猜测:

Button Grid.Row="1" (in XAML)

SetRow (from Grid) will be executed. SetRow(来自Grid)将被执行。 PropertyChangedCallback (initialized in metadata) will be triggered also. PropertyChangedCallback(在元数据中初始化)也会被触发。 I suppose that Grid will assign Button by some code in this Callback, but it makes no sense for me... Callback will get DepedencyObject (= Grid instance) and EventArgs (= value). 我想Grid将在此Callback中通过一些代码分配Button,但是对我来说这没有意义... Callback将获得DepedencyObject(= Grid实例)和EventArgs(= value)。 How grid can know which object changed Attached Dependency Property? 网格如何知道哪个对象更改了附加依赖项属性? Grid should have its own storage for objects position... How does Grid save that information? 网格应具有自己的对象位置存储...网格如何保存该信息?

Thanks in advance for explanation. 在此先感谢您的解释。

  1. Right, there are static dictionaries of some kind that associate the objects with their values (at various levels, styles, local values etc. The value is determined via precedence ). 正确,有一些静态字典将对象与它们的值(在各个级别,样式,局部值等)相关联。该值是通过priority确定的。 The internals should not matter to you. 内部结构对您来说并不重要。
  2. Wrong, the dependency object on which the property was set is passed to the callback, not the grid. 错误的是,在其上设置了属性的依赖项对象传递给了回调,而不是网格。 (There is no grid instance to be found directly anyway, the grid instance then is found via VisualTreeHelper.GetParent ). (仍然没有直接找到的网格实例,然后可以通过VisualTreeHelper.GetParent找到该网格实例)。 The mechanism probably works via looping through the Grid.Children during the layout pass and getting the properties of those to determine where everything should go. 该机制可能是通过在布局过程中遍历Grid.Children并获取那些属性来确定所有内容的位置而Grid.Children的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM