C# 为什么不显示弹出窗口?

C# 为什么不显示弹出窗口?,c#,windows-phone-7.1,C#,Windows Phone 7.1,第一: 然后: 公共Verdien(内部调度条件=20,内部调度条件=8) { this.attesainsecondiiziale=attesainsecondiziale; this.attesainsecondIInizale=attesainsecondIInizale; MostraPerQuestaSezione=假 public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHa

第一:

然后: 公共Verdien(内部调度条件=20,内部调度条件=8) { this.attesainsecondiiziale=attesainsecondiziale; this.attesainsecondIInizale=attesainsecondIInizale; MostraPerQuestaSezione=假

public MainPage()
{
    InitializeComponent();

    this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    Verdienen v = new Verdienen(4, 3);
}
popup=newpopup();
边框=新边框();
border.Background=新的SolidColorBrush(颜色为浅灰色);
边界。边缘=新厚度(3);
StackPanel panelVerticale=新的StackPanel();
PanelVertical.Orientation=Orientation.Vertical;
AdControl control=新的AdControl();
panelVerticale.Children.Add(控件);
StackPanel panelOrizzontale=新的StackPanel();
panelOrizzontale.Orientation=Orientation.Horizontal;
按钮bAltreApp=新按钮();
bAltreApp.Content=“”;
bAltreApp.Tap+=新事件处理程序(bAltreApp\u Tap);
按钮bVota=新按钮();
bVota.Tap+=新事件处理程序(bVota_Tap);
bVota.Content=“”;
panelOrizzontale.Children.Add(bAltreApp);
panelOrizzontale.Children.Add(bVota);
panelVerticale.Children.Add(panelOrizzontale);
border.Child=垂直面板;
popup.Child=边框;
this.ShowPopup();
}
私有异步**System.Threading.Tasks.TaskEx**ShowPopup()
{
做
{
Debug.WriteLine(“线程地址为pausa cominciata”);
等待系统。线程。任务。任务执行延迟(1000*this.attensecondiiziale);
WriteLine(“线程:fine pausa”);
popup.IsOpen=true;
等待系统.Threading.Tasks.TaskEx.Delay(1000*this.attenseCondifinale);
popup.IsOpen=false;
}while(MostraPerQuestaSezione);
}
你能告诉我为什么这个代码没有显示弹出窗口吗?注意:一些不必要的代码不存在!
编辑:请注意,System.Threading.Tasks.TaskEx标记为错误(“异步方法的返回状态必须为void、Task或Task”)。

使用
Thread.Sleep
时,会阻止UI消息泵。这会阻止系统显示弹出窗口,因为只有正确处理消息后才会显示弹出窗口

更好的方法是将其移动到异步方法中,并在构造后调用它:

        popup = new Popup();
        Border border = new Border();
        border.Background = new SolidColorBrush(Colors.LightGray);
        border.Margin = new Thickness(3);
        StackPanel panelVerticale = new StackPanel();
        panelVerticale.Orientation = Orientation.Vertical;
        AdControl control = new AdControl();
        panelVerticale.Children.Add(control);
        StackPanel panelOrizzontale = new StackPanel();
        panelOrizzontale.Orientation = Orientation.Horizontal;
        Button bAltreApp = new Button();
        bAltreApp.Content = "";
        bAltreApp.Tap += new EventHandler<GestureEventArgs>(bAltreApp_Tap);
        Button bVota = new Button();
        bVota.Tap += new EventHandler<GestureEventArgs>(bVota_Tap);
        bVota.Content = "";
        panelOrizzontale.Children.Add(bAltreApp);
        panelOrizzontale.Children.Add(bVota);
        panelVerticale.Children.Add(panelOrizzontale);
        border.Child = panelVerticale;
        popup.Child = border;

        this.ShowPopup();
    }

    private async **System.Threading.Tasks.TaskEx** ShowPopup()
    {
        do
        {
            Debug.WriteLine("thread iniziato. pausa cominciata");
            await System.Threading.Tasks.TaskEx.Delay(1000 *    this.AttesaInSecondiIniziale);
            Debug.WriteLine("thread: fine pausa");
            popup.IsOpen = true;
            await System.Threading.Tasks.TaskEx.Delay(1000 * this.AttesaInSecondiFinale);
            popup.IsOpen = false;
        } while (MostraPerQuestaSezione);
    }
通过在异步方法中将
Task.Delay
await
一起使用,您不会阻塞UI。然而,这需要以WP7.5为目标

应该是

this.ShowPopup(); ...
this.HidePopup();
您正在调用
this
,在此上下文中,
this
是一个
Verienen
对象,您没有


ShowPopup()
HidePopup()
方法

ShowPopup的代码在哪里?我已经升级了代码。请下次再看!好的…但是如何添加系统。线程。任务??我只能添加系统线程。。。我在我的项目中使用了“PM>installpackagesystem.Threading.Tasks-Pre”,但没有添加它…对不起,它似乎是在等待任务。延迟(int)将仅从WP8@Spode如果您的目标是7.5,那么它将是
wait TaskEx.Delay(int)
是的,但我遇到了一个错误,如第一篇文章所述。请另找时间。System.Threading.Tasks.TaskEx被标记为错误(“异步方法的返回状态必须为void、Task或Task”)。不……我不相信它是解决方案,因为我声明了Popup Popup作为全局变量。谢谢!=)那么这是什么?如果它没有引用
Verdienen()
的对象,那么我对C#和OOP的理解就大相径庭了。复杂的是的,这是指Verdien的例子。但正是在这个类中,我将Popup声明为全局对象;)
this.ShowPopup(); ...
this.HidePopup();
popup.ShowPopup(); ...
popup.HidePopup();