我正在使用WPF/XAML,并基于
window
打电话
container
.
容器
具有名为的DependencyProperty
CurrentElementProperty
链接到属性
CurrentElement
。我的问题是
set
从未从调用属性的方法
DerivedContainer
。如果我更改
typeof(Container)
到
typeof(DerivedContainer)
在属性注册过程中,它被调用。我几乎可以肯定,我在注册过程中做错了什么。
定义
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,共个
派生容器
(我删除了标准的XML命名空间定义)
<local:Container x:Class="ns.DerivedContainer"
xmlns:local="clr-namespace:ns">
<local:Container.CurrentElement>
<Element />
</local:Container.CurrentElement>
</local:Container>
代码隐藏
派生容器
public partial class DerivedContainer : Container
{
public DerivedContainer()
{
InitializeComponent();
}
}