简体   繁体   English

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

[英]Caliburn Micro not updating dependency property in User Control

I have a Caliburn Micro View/ViewModel set which is utilizing a User Control which has one of its dependency properties bound to a value which is in the ViewModel of the main view. 我有一个Caliburn Micro View / ViewModel集合,它使用一个用户控件,该控件的依赖项属性之一绑定到一个位于主视图的ViewModel中的值。 I can't seem to get the User Control to be notified when the value in the ViewModel changes. 当ViewModel中的值更改时,似乎无法通知用户控件。

ViewModel: ViewModel:

OutputImage.AddDirtyRect(new Int32Rect(0, 0, width, height));
OutputImage.Unlock();

NotifyOfPropertyChange(() => OutputImage);

Main View: 主视图:

<local:HistogramControl x:Name="Histogram" Grid.Row="1" Grid.Column="0" OutputImage="{Binding Path=OutputImage, Mode=TwoWay}"/>

User Control: 用户控制:

    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); }
    }

If I place a break point in the user control code in the PropertyChangedCallback(...) lambda it will be hit once when the application starts and the initial OutputImage set in the constructor of the ViewModel class is provided, but it will not be called again when the ViewModel code shown above is called and the OutputImage changes. 如果我将断点放在PropertyChangedCallback(...) lambda中的用户控制代码中,则它将在应用程序启动时被命中一次,并提供了在ViewModel类的构造函数中设置的初始OutputImage,但不会调用它再次调用上面显示的ViewModel代码,并且OutputImage更改。

The problem is that the WriteableBitmap was modified via pointers to its memory in unsafe code since image data was being copied into the pixel buffer. 问题在于,由于图像数据已被复制到像素缓冲区中,因此WriteableBitmap通过不安全代码中指向其内存的指针进行了修改。 This didn't trigger a binding update since the object bound wasn't really updated. 由于绑定的对象并未真正更新,因此未触发绑定更新。 Since the binding is via reference the pixel data in the bound value inside the user control was updated as it was changed, there just was no notification via a call to the PropertyChangedCallback(...) . 由于绑定是通过引用进行的,因此用户控件内绑定值中的像素数据会随着更改而进行更新,因此通过调用PropertyChangedCallback(...)不会收到任何通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM