Caliburn Micro 未更新用户控件中的依赖项 属性

Caliburn Micro not updating dependency property in User Control

我有一个 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 class 的构造函数中设置的初始 OutputImage 是提供了,但是调用上面的ViewModel代码,OutputImage发生变化时,不会再调用。

问题在于,由于图像数据被复制到像素缓冲区,WriteableBitmap 已通过指向其内存的指针在不安全代码中进行了修改。这并没有触发绑定更新,因为对象绑定并没有真正更新。由于绑定是通过引用进行的,因此用户控件内绑定值中的像素数据会在更改时进行更新,因此不会通过调用 PropertyChangedCallback(...).

进行通知