Reputation: 127
I've created a basic Metro App for Win 8 using Visual Studio 11 Ultimate in C#.
The problem here is that I want to display text that dynamically changes with certain events. An example would be an app where a number is displayed on the screen and increments by 1 whenever the mouse is clicked.
I've using XAML binding to a data structure I've created which does get the values I need to display, but the problem is that as those values change, the numbers that display on the GUI do not change.
How do I bind my XAML to data that dynamically changes so that the XAML display on the GUI changes as well?
Thanks for the help!
-- edit --
I've implemented the INotifyPropertyChanged interface, but now I'm receiving an Exception from this line of code:
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
Here is the Exception information:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
Upvotes: 5
Views: 4085
Reputation: 564413
Make sure your "data structure" you're binding to (properly) implements INotifyPropertyChanged and invokes the PropertyChanged event when you want to notify the UI of a change.
This is the interface that allows the xaml layer to know when values change in the bound data, and update accordingly.
Edit in response to new information:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
This suggests you're raising the property changed from a separate thread, which will potentially cause issues. You may need to marshal this back to the main thread using CoreDispatcher.RunAsync. For details, see this thread.
Upvotes: 7