1

As we know, Delegate has two properties, one is for method infor and the other is for the target object. but it is very strange on WinRT. if a view model implement INotifyPropertyChanged as below:

public class PropertyChangedViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged
    {
        add { /*some code to add handler of value*/ }
        remove { /*some code to removehandler of value*/ }
    }
}

in the method "add" and "remove" I find the value.Target is null when this event is used by the internal code of XAML binding. That is to say, if I bind some property of the view model on the xaml file, then the winrt will automaticlly register the event PropertyChanged of this view model, and then the add method is call, but I placed a break point in this add method and find the Target of value is null. I'm implementing a cross platfrom mvvm library (for wpf, winrt, silverlight and wp 7+) so I can't use PropertyChangedEventManager, I have to manually to keep a weak reference to the target and then invoke the method with the target, unfortunately, the targer is null, while the method is not a static method, so when I triger this event later, I get exception. Is there any workaround?

Thanks!

4

0 回答 0