【问题标题】:UWP - how can we repeat the display of 3 static text messages via a local tile notificationUWP - 我们如何通过本地磁贴通知重复显示 3 条静态文本消息
【发布时间】:2020-10-07 19:40:51
【问题描述】:

环境Windows 10 Pro - v1903VS2019 - v16.6.2

使用 Microsoft 文档中的 sample code,我能够创建一个带有文本消息的磁贴,如下所示。但是我想在一定的时间间隔内显示3条不同的静态短信。

问题:在上面的磁贴示例中,我们如何通过本地磁贴通知重复显示 3 条不同的静态文本消息。例如:

每 10 分钟:在第一个时间间隔内显示 This is message 1,在接下来的 10 分钟内显示 This is message 2,在接下来的 10 分钟内显示 This is message 3。然后重新开始每 10 分钟显示 3 条消息。

有一些使用服务器、服务、实时提要等后台任务的示例。但我只需要使用静态文本消息在本地完成。

【问题讨论】:

    标签: c# uwp uwp-xaml windows-community-toolkit


    【解决方案1】:

    我们如何通过本地磁贴通知重复显示 3 条静态文本消息

    对于描述,它看起来像逻辑问题,而不是磁贴通知本身。如果要重复显示磁贴内容,可以让DispatcherTimerTimer_Tick事件中调用showTile方法,并使用int count记录当前次数,如果count等于3则归零。更多内容请参考以下示例代码。

    public MainPage()
    {
        this.InitializeComponent();
        DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMinutes(10) };
        timer.Tick += Timer_Tick;
        timer.Start();
    
    }
    
    private int count = 0;
    private void Timer_Tick(object sender, object e)
    {
        count++;
        if (count == 3)
        {
            count = 0;
        }
    
        switch (count)
        {
            case 0:
                showTile("First");
                break;
            case 1:
                showTile("First", "Second");
                break;
            case 2:
                showTile("First", "Second", "Third");
                break;
            default:
                break;
        }
    }
    

    【讨论】:

    • @NicoZhuMSFT 您的解决方案有效。但我认为你的意思是在case 0 中调用showTile("First")case 1 中的showTile("Second")case 2 中的showTile("Third")。您可能误解了我的情况,或者我可能不是很清楚。感谢您的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多