I'm working with WPF/XAML and defined my own view based on window called container. container has a DependencyProperty called CurrentElementProperty linked to the property CurrentElement. My problem is that the set method of the property is never called from DerivedContainer. If I change the typeof(Container) to typeof(DerivedContainer) during property registering it gets called. I'm almost certain, I'm doing something wrong during registering.
Definition of Container
class Container : Window
{
public static readonly DependencyProperty CurrentElementProperty =
DependencyProperty.Register(
"CurrentElement",
typeof(Element),
typeof(Container),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.Inherits));
public Element CurrentElement
{
get
{
return (Element)this.GetValue(Container.CurrentElementProperty);
}
set
{
this.SetValue(Container.CurrentElementProperty, value);
}
}
}
XAML of DerivedContainer (I removed the standard XML namespace definitions)
<local:Container x:Class="ns.DerivedContainer"
xmlns:local="clr-namespace:ns">
<local:Container.CurrentElement>
<Element />
</local:Container.CurrentElement>
</local:Container>
Code behind DerivedContainer
public partial class DerivedContainer : Container
{
public DerivedContainer()
{
InitializeComponent();
}
}