UWP - how can we repeat the display of 3 static text messages via a local tile notification

纵然是瞬间 提交于 2020-07-10 07:31:19

问题


Environment: Windows 10 Pro - v1903, VS2019 - v16.6.2

Using this sample code from Microsoft docs, I was able to create a tile - with a text message - as shown below. But I would like to display 3 different static text messages in a certain interval.

Question: In the above tile example, how can we repeat the display of 3 different static text messages via a local tile notification. For example:

Every 10 minutes: Display This is message 1 in the first interval, This is message 2 during next 10 minutes, This is message 3 during next 10 minutes. Then start over displaying same 3 messages every 10 minutes.

There are some examples using background tasks using servers, services, live feeds etc. But I need just to do it locally with static text messages.


回答1:


how can we repeat the display of 3 static text messages via a local tile notification

For the description, it looks like logic problem, but not tile notification itself. if you want to repeat show the tile content, you could make DispatcherTimer to call showTile method within Timer_Tick event, and use int count to record current times, if the count equal to 3, then return to zero. For more please refer the following sample code .

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;
    }
}


来源:https://stackoverflow.com/questions/62438283/uwp-how-can-we-repeat-the-display-of-3-static-text-messages-via-a-local-tile-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!