我无法理解发生在我身上的问题。何时触发PropertyChangedCallback
我有一个UserControl的结构很像这样。
public class SomePage : Page
{
public static readonly DependencyProperty SomePropertyProperty =
DependencyProperty.Register("SomeProperty", typeof(IPropertyValue), typeof(SomeControl), new PropertyMetadata(null, new PropertyChangedCallback(OnSomePropertyChanged)));
private static void OnSomePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//Do Some Stuff
}
}
这看起来像一个ViewModel这
public class SomeViewModel : BindableBase
{
private IPropertyValue _prop;
public IPropertyValue Property
{
get
{
if (_prop== null)
_prop = new SomeConcreteValue();
return _prop;
}
}
}
而整个东西是绑定到一个页面
<common:LayoutAwarePage>
<Page.DataContext>
<vm:SomeViewModel />
</Page.DataContext>
<ctrl:SomePage SomeProperty="{Binding Property}" />
</common:LayoutAwarePage>
在我的理解中PropertyChangedCallbacked被称为每当DependencyProperty的值变化。
虽然ViewModel.Property的值永远不会改变,但DependencyProperty“SomeProperty”的值仍然存在,因为它从null更改为初始值。
有没有其他的可能性,一旦房产被初始化或得到通知我,我只是失去了一些东西?
编辑: 也许我不清楚这一点。我的问题是,当初始值设置为SomeProperty时,PropertyCahngedCallback未被触发。
你到底想干什么? – mydogisbox
我编辑了这个问题。当初始值设置为_SomeProperty_时,我需要得到通知。 – Robert