Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating GUI of Windows 8 C# Metro App

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

like image 423
Joshua Mak Avatar asked May 25 '12 17:05

Joshua Mak


People also ask

How do you update Control Panel in Windows 8?

To check for Windows 8.1 updates, click Start > Control Panel > System and Security > Windows Update > Check for Updates. The window will show any available updates. If there are available updates, click on Install updates and follow the instructions.

Can Windows 8.1 be updated?

No. Support for Windows 8.1 is discontinued, but the software will continue to function. However, after January 10, 2023, your computer running Windows 8.1 will no longer receive security updates.

Is Windows 8 GUI based operating system?

Windows 8 operating system introduced major changes over its predecessor operating system Windows 7. Windows 8 has a different GUI which is also designed for tablets, mobile devices, USB 3.0 support, Windows Store in order to download and install applications from a centralized market place, ARM processor support, etc.


1 Answers

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.

like image 63
Reed Copsey Avatar answered Sep 20 '22 12:09

Reed Copsey