I am trying to update my page elements but some how my program crashes during update. /*

 MainPage::MainPage()
    {
        InitializeComponent();
        ApplicationData::Current->DataChanged += ref new TypedEventHandler<ApplicationData^, Object^>
        (this, &MainPage::DataChangedHandler);
    }

    void MainPage::DataChangedHandler(Windows::Storage::ApplicationData^ appData, Object^)
    {
        this->UpdateUIElements();
    }

*/

有帮助吗?

解决方案

The problem is you need to run the update asynchronously in the ui thread.

void MainPage::DataChangedHandler(Windows::Storage::ApplicationData^ appData, Object^)
{
    Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler(
        [this]()
        {
        UpdateUIElements();
        }));
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top