1

我有一个附加属性:

public static readonly DependencyProperty DataTableProperty =
    DependencyProperty.RegisterAttached("DataTable",
    typeof(MetadataTable),
    typeof(TabControl),
    new PropertyMetadata(DataTableChanged));

我像这样使用它,一切都正确构建:

<sdk:TabControl view:DataBrowserHelper.DataTable="{Binding Path=Table}" />

如果我将属性的 ownerType 更改为另一种类型,一切仍然正确构建。我认为 ownerType 确定了可附加到的属性的类型。所以我错了?什么是所有者类型?以及如何限制属性的使用(例如,使其只能附加到 TabControl 或 DataGrid)?

4

1 回答 1

1

ownerType 是拥有该属性的类的类型。例如,如果您在名为 MyClass 的类中声明此属性,则此 DependencyProperty 的 ownerType 将为 MyClass。

限制使用很复杂,因为您的程序只会在运行时知道您在接口上附加到 DP 的元素的类型,所以它会在您手中正确执行。

于 2012-05-17T13:54:43.643 回答