UWP - 我们如何通过本地磁贴通知重复显示 3 条静态文本消息
UWP - how can we repeat the display of 3 static text messages via a local tile notification
环境:Windows 10 Pro - v1903
、VS2019 - 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 条消息。
有一些使用服务器、服务、实时提要等后台任务的示例。但我只需要在本地使用静态文本消息进行操作。
how can we repeat the display of 3 static text messages via a local tile notification
根据描述,看起来像是逻辑问题,而不是磁贴通知本身。如果要重复显示tile内容,可以让DispatcherTimer
在Timer_Tick
事件中调用showTile方法,用int count记录当前次数,如果count等于3,则return 归零。更多请参考下面的示例代码。
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;
}
}
环境:Windows 10 Pro - v1903
、VS2019 - 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 条消息。
有一些使用服务器、服务、实时提要等后台任务的示例。但我只需要在本地使用静态文本消息进行操作。
how can we repeat the display of 3 static text messages via a local tile notification
根据描述,看起来像是逻辑问题,而不是磁贴通知本身。如果要重复显示tile内容,可以让DispatcherTimer
在Timer_Tick
事件中调用showTile方法,用int count记录当前次数,如果count等于3,则return 归零。更多请参考下面的示例代码。
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;
}
}