Question

I have an attached property:

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

I use it like this and everything builds correctly:

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

If i change the ownerType of the property to another type, everything still builds correctly. I thought the ownerType determines the type which is the property attachable to. So I was wrong? What is the ownerType? And how can I restrict the usage of the property (for example make it attachable only to the TabControl or DataGrid)?

Was it helpful?

Solution

ownerType is the type of the class that owns the property. For example, if you are declaring this property in a class named MyClass , the ownerType of this DependencyProperty will be MyClass.

Restrict the usage is complicated because your program will know the type of the element you're attaching to the DP on the interface only in RunTime, so it'll be in your hands do it right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top