Windows Phone 8.1 - ContentDialog永远不会被隐藏

时间:2015-02-04 18:59:02

标签: c# windows-runtime windows-phone windows-phone-8.1

在我的Windows Phone 8.1应用程序中,我使用ContentDialog显示一些数据。当我调用contentDialog.ShowAsync();它按预期显示,但是当我尝试隐藏它时,对话框保持在屏幕上。

我的代码如下:

StackPanel stackPanel = new StackPanel();
ProgressBar progressBarDialog = new ProgressBar();
progressBarDialog.Width = 300;
progressBarDialog.Height = 10;
progressBarDialog.IsIndeterminate = true;

TextBlock textBlockDialog = new TextBlock();
textBlockDialog.Text = "Loading...";
textBlockDialog.FontSize = 17;
textBlockDialog.Foreground = new SolidColorBrush(Colors.White);
textBlockDialog.HorizontalAlignment = HorizontalAlignment.Center;

stackPanel.Children.Add(progressBarDialog);
stackPanel.Children.Add(textBlockDialog);

ContentDialog contentDialog = new ContentDialog();
contentDialog.Content = stackPanel;
SolidColorBrush color = new SolidColorBrush(Colors.Black);
color.Opacity = 0.7;
contentDialog.Background = color;
contentDialog.Margin = new Thickness(0, 250, 0, 0);

await contentDialog.ShowAsync();
//Perform long operations
contentDialog.Hide();

因此,对话框显示没有任何问题,但它永远不会被隐藏。

有什么想法吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试使用此:

var t =  contentDialog.ShowAsync();
t.Cancel();