【发布时间】:2017-01-26 03:46:50
【问题描述】:
我正在用 C# 编写一个 Windows 10 桌面应用程序(不是通用应用程序,这很重要),它需要发送一个 toast 通知,其中包括一个文本框和一个提交按钮。
我使用ToastNotification.Activated 来收听单击提交按钮的时间,但我找不到任何方法从吐司中提取文本框文本。
我发现的所有方法——包括 MSFT 文章 here 和 StackOverflow 给出的答案 here,似乎只适用于通用应用程序,我无法将它们应用到桌面应用程序。
关于如何从 Win10 桌面 应用上的 toast 中提取文本框文本输入的任何线索?
下面附上我的代码sn-p
谢谢
private void ShowToastButton_Click(object sender, RoutedEventArgs e)
{
string toastXmlString=$@"
<toast action='submit'>
<visual>
<binding template='ToastGeneric'>
<text hint-maxLines='1'>Line1</text>
<text>Line2</text>
</binding>
</visual>
<actions>
<input id='textBox' type='text' placeHolderContent='text' />
<action
content='Submit'
hint-inputId='textBox'
arguments='action=text' />
</actions>
</toast>";
Windows.Data.Xml.Dom.XmlDocument toastCustomtXml = new Windows.Data.Xml.Dom.XmlDocument();
toastCustomtXml.LoadXml(toastXmlString);
// Create the toast and attach event listeners
ToastNotification toast = new ToastNotification(toastCustomtXml);
toast.Activated += ToastActivated;
toast.Dismissed += ToastDismissed;
toast.Failed += ToastFailed;
// Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
}
private void ToastActivated(ToastNotification sender, object e)
{
// This event is fired, but I can't extract the textbox text
// 'e' is a ToastActivatedEventArgs object, e.Arguments == 'action=text'
Dispatcher.Invoke(() =>
{
Activate();
Output.Text = "The user activated the toast.";
});
}
【问题讨论】:
-
你指的是什么桌面应用?只需创建一个 uwp 应用和目标桌面?
-
@Sunteen-MSFT 我的应用不是 UWP 应用,而是标准 C# 桌面程序。我无法切换到 UWP 应用,因为它非常受限制,而且我的某些功能无法使用。
-
您好,我知道这是一篇旧帖子,但您找到解决方法了吗?我有同样的问题,我正在寻找解决方案。如果有任何有用的建议,我会很高兴的。
-
@bensvk 不,我最终为此编写了一个特殊的 UWP 应用程序,它与我的主应用程序(非 uwp)进行通信。完全荒谬。不过,我已经离开桌面应用游乐场有一段时间了,所以从那以后情况可能会发生变化。
标签: c# windows notifications windows-10 desktop-application