Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

Microsoft loves MVVM and INotifyPropertyChanged so much that they included this very useful interface twice in the new WinRT framework. Unfortunately, only one of these is working correctly (and the other one is likely a bug, remnant from the past Winking smile)

When implementing INotifyPropertyChanged, make sure that you select the correct one! The one you want to use is into Windows.UI.Xaml.Data. The old one, the one you DON’T WANT is into System.ComponentModel (the same namespace it was in WPF and Silverlight). If you select the wrong one, the Bindings will not be updated and the UI will remain dead as a dead fish.

I mentioned before that Microsoft took the “once in a lifetime” opportunity (well, 5-10 years is a lifetime in the world of computers) to clean up and rearrange classes within the framework. This is one of the signs right here. As for the System.ComponentModel.INotifyPropertyChanged, I guess it will be removed in a later release of the WinRT framework.

Update: Indeed I was just told by the excellent and always vigilant Tim Heuer that this bug has already been fixed. I guess we will see the fix in the next release to developers of Windows 8.

Cheers,

Laurent

 

Print | posted on Sunday, September 25, 2011 10:47 PM

Feedback

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Paul Osterhout at 9/25/2011 11:14 PM Gravatar
Based upon my understanding, you can still write .NET apps that don't use the WinRT for backward compatibility purposes (non-Metro UI apps). So I would think the System.ComponentModel version is there for that purpose.

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Ian Smith at 9/25/2011 11:17 PM Gravatar
This seems to slightly contradict the information given in Session 529 where it was suggested that Windows needed to be used for Metro/WinRT environment and System needed to be used for Desktop environment (and yes, he thought it was a bug).

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Laurent at 9/26/2011 12:20 AM Gravatar
Paul, you are right that you can indeed write .NET applications that run on Windows 8, however this is a different framework (.NET vs WinRT).

WinRT exposes some classes in the Windows namespace and others in the System namespace. But the WinRT System namespace is not the same as the .NET System namespace. Typically, what was moved from System into Windows in WinRT was then deleted from System.

Tim Heuer just confirmed that this has been fixed, so even if he didn't use that word, I would say it is indeed a bug in the developer preview.

Cheers
Laurent

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Dany Laporte at 9/26/2011 12:14 PM Gravatar
I hope that the namespace is the same for both (Metro style apps and classic .net Apps) because the viewmodel won't be portable. I don't like to have conditional compilation everywhere in my code.

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Ido Ran at 10/7/2011 8:08 AM Gravatar
Hi,
You say that it's a bug and it has been fixed - what was fixed? Are there still two interfaces or not?

Thank you,
Ido.

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Laurent at 10/7/2011 8:31 AM Gravatar
To be honest I am not sure. I was just told it was fixed. I think the Sys.ComponentModel interface will be removed.

Cheers
Laurent

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Darren Mart at 10/20/2011 10:08 PM Gravatar
Wish I would've found your blog yesterday, burnt almost 2 hours last night trying to figure out why binding wasn't working on a class I'd ported over from Silverlight.

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by philly at 1/11/2012 5:00 PM Gravatar
They don't love MVVM so much if they put interfaces like INotifyPropertyChanged in a XAML dll, that breaks MVVM.

# re: Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

left by Laurent Bugnion at 1/12/2012 7:47 PM Gravatar
Hi,

How so? INPC makes a lot of sense for XAML based WinRT, but not for HTML based WinJS, so why would you consider that it breaks MVVM in any way?

Cheers,
Laurent
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: