【问题标题】:Frame Navigation UWP框架导航 UWP
【发布时间】:2020-08-06 05:19:17
【问题描述】:

嘿,我想做一些类似幻灯片的东西,您可以在其中启动应用程序,然后它会遍历页面,但程序不会加载。

        public MainPage()
    {
        this.InitializeComponent();
        while (true)
        {
            this.contentFrame.Navigate(typeof(Page1));
            Thread.Sleep(10000);
            this.contentFrame.Navigate(typeof(werbungPage));
            Thread.Sleep(10000);
            this.contentFrame.Navigate(typeof(ChartZielPage));
            Thread.Sleep(10000);
            this.contentFrame.Navigate(typeof(mitarbeiteronlinePage));
            Thread.Sleep(10000);
            this.contentFrame.Navigate(typeof(MomentaneKundenPage));
            Thread.Sleep(10000);
            this.contentFrame.Navigate(typeof(OutlookKalenderPage));
            Thread.Sleep(10000);
            this.contentFrame.Navigate(typeof(ChartServerPage));
            Thread.Sleep(10000);
            this.contentFrame.Navigate(typeof(ChartWheaterPage));
            Thread.Sleep(10000);
        }
    }

【问题讨论】:

    标签: c# .net visual-studio uwp uwp-xaml


    【解决方案1】:

    嘿,我想做一些类似幻灯片的东西,您可以在其中启动应用程序,它会遍历页面,但程序不会加载。

    问题是Thread.Sleep造成UI线程死锁,根据您的要求,我们建议使用DispathcerTimer处理幻灯片导航。

    private int index;
    private List<Type> pages = new List<Type>() { typeof(TestPage), typeof(BlankPage), typeof(BlankPage) };
    public MainPage()
    {
        this.InitializeComponent();
    
        var timer = new DispatcherTimer();
        timer.Interval = TimeSpan.FromSeconds(2);
        timer.Tick += Timer_Tick;
        timer.Start();
    }
    
    private void Timer_Tick(object sender, object e)
    {
        if (index == pages.Count)
        {
            index = 0;
        }
        this.contentFrame.Navigate(pages[index]);
        index++;    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-31
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多