WinRT C++: Raising PropertyChanged event on a GUI Thread

If you are a WPF developer you don’t have to raise the PropertyChanged even on a GUI Thread, but it seems as though same pattern in C++ WinRT Windows Store component requires this even to be raised on a GUI Thread.

I happened to stuble upon another blog ( which helped me with my Unit Testing (  It happened to refer to a project on CodePlex called Hilo.  Looking at the source code in the TestHelper.cpp class (TestHelper.cpp) I found helpful code.  Adapted it below:

In the .h file:

namespace RSSParser
  public ref class ViewModel sealed : public INotifyPropertyChanged
    void RaisePropertyChanged(String^ propertyName);

In the CPP file:

void ViewModel::RaisePropertyChanged(String^ property)
     CoreDispatcher^ dispatcher = CoreApplication::MainView->CoreWindow->Dispatcher;
       ref new Windows::UI::Core::DispatchedHandler([=] () -> void
       PropertyChanged(this, ref new PropertyChangedEventArgs(property));


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s