문제

I'm trying to call a MessageDialog out of a PropertyChanged Handler. The first call is always successful, but when the Dialog gets called a second time, I get an UnauthorizedAccessException.

I've tried to wrap the call in a Dispatcher, but I got the same behavior.

Here's the code (snippet of MainPage.xaml.cs):

void PropertyChanged(object sender, PropertyChangedEventArgs e)
{
  await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  {
    showMessage("Message", "Title");
  });
}

async void showMessage(String message, String title)
{
  MessageDialog dialog = new MessageDialog(message, title);
  await dialog.ShowAsync();
}

Could anybody please help me with this issue?

도움이 되었습니까?

해결책

I think your problem is that multiple property changes will cause multiple calls to display the dialog. You should only ever display one dialog at a time:

bool _isShown = false;
async void showMessage(String message, String title)
{
    if (_isShown == false)
    {
        _isShown = true;

        MessageDialog dialog = new MessageDialog(message, title);
        await dialog.ShowAsync();

        _isShown = false;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top