views:

23

answers:

1

Is it possible to have a dependency property "DataContext" in a class that is NOT derived from "FrameworkElement" (but it can be derived from "DependencyObject")?

I already tried and created a class (which I added to Window.Resources), but the DataContext is always null.

Any ideas?

A: 

Have you tried to use the AddOwner method? Example (FrameworkContentElement):

DataContextProperty = FrameworkElement.DataContextProperty.AddOwner(typeof(FrameworkContentElement), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, new PropertyChangedCallback(FrameworkContentElement.OnDataContextChanged)));

If you leave out the callback/options .. it might work.

Martin