0

Why following code (thanks to Aybe) hangs at line var result = await dialog1.ShowAsync(); I was expecting it to get a simple user input and continue after user clicks OK. But the dialog UI does not even completely shows up. It just hangs with all white background. I just see on top of main window there is a small dialog window with white background and it just hangs there.

I've seen solutions to such issues such as here. But as this solution suggests I'm using async on Button_Click event. The difference between the referenced solution and mine is that I'm using UWP and they are probably not. So, what I may be missing and how we can resolve the issue?

private async void myButton_ClickAsync(object sender, RoutedEventArgs e)
{
  var dialog1 = new ContentDialog1();
  var result = await dialog1.ShowAsync(); //hangs here

  if (result == ContentDialogResult.Primary)
  {
     var text = dialog1.Text;
  }
  ....
  ....
}

Custom Dialog class:

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace App1
{
    public sealed partial class ContentDialog1 : ContentDialog
    {
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
            "Text", typeof (string), typeof (ContentDialog1), new PropertyMetadata(default(string)));

        public ContentDialog1()
        {
            InitializeComponent();
        }

        public string Text
        {
            get { return (string) GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
        }

        private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
        }
    }
}

UPDATE:

I'm using latest versions of both VS2017 and Windows 10 Professional Laptop. No tapping (touch device) or smart phone or tablet is involved.

nam
  • 21,967
  • 37
  • 158
  • 332
  • https://stackoverflow.com/q/32770422/11683? – GSerg Jun 02 '19 at 15:52
  • Your code did work for me. The contentDialog worked well on my side. I cannot reproduce your issue. What's your OS build version and project's target version? – Xie Steven Jun 04 '19 at 02:41

1 Answers1

0

In doing exactly what you do, I'm able to successfully show the dialog.

There is either something we're not seeing in the code provided, or something because it works just fine.

Going-gone
  • 282
  • 1
  • 14