【发布时间】:2013-05-19 17:59:40
【问题描述】:
我无法理解发生在我身上的问题。
我有一个类似这样结构的 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>
据我了解,只要 DependencyProperty 的值发生变化,就会调用 PropertyChangedCallbacked。
尽管 ViewModel.Property 的值永远不会改变,但 DependencyProperty“SomeProperty”的值仍然会改变,因为它从 null 变为初始绑定值。
一旦属性被初始化或者我只是在这里遗漏了一些东西,是否还有其他可能得到通知?
编辑: 也许我并不清楚这一点。我的问题是当初始值设置为 SomeProperty 时不会触发 PropertyCahngedCallback。
【问题讨论】:
-
你想做什么?
-
我已经编辑了这个问题。当初始值设置为 SomeProperty 时,我需要得到通知。
标签: wpf data-binding mvvm windows-8 dependency-properties