【发布时间】:2015-05-16 19:35:01
【问题描述】:
我有一个 Caliburn Micro View/ViewModel 集,它使用一个用户控件,该控件的一个依赖属性绑定到主视图的 ViewModel 中的一个值。当 ViewModel 中的值发生更改时,我似乎无法通知用户控件。
视图模型:
OutputImage.AddDirtyRect(new Int32Rect(0, 0, width, height));
OutputImage.Unlock();
NotifyOfPropertyChange(() => OutputImage);
主视图:
<local:HistogramControl x:Name="Histogram" Grid.Row="1" Grid.Column="0" OutputImage="{Binding Path=OutputImage, Mode=TwoWay}"/>
用户控制:
public static readonly DependencyProperty OutputImageProperty =
DependencyProperty.Register("OutputImage", typeof(BitmapSource), typeof(HistogramControl), new UIPropertyMetadata(
new WriteableBitmap(1, 1, 96, 96, PixelFormats.Rgb24, null),
new PropertyChangedCallback((s, e) =>
{
var source = s as HistogramControl;
source.UpdateHistogram();
})));
public BitmapSource OutputImage
{
get { return (BitmapSource)GetValue(OutputImageProperty); }
set { SetValue(OutputImageProperty, value); }
}
如果我在PropertyChangedCallback(...) lambda 中的用户控件代码中放置一个断点,它将在应用程序启动时命中一次,并提供 ViewModel 类的构造函数中设置的初始 OutputImage,但它不会被调用再次调用上面显示的 ViewModel 代码并且 OutputImage 发生变化。
【问题讨论】:
标签: c# wpf mvvm dependency-properties caliburn.micro