powershell - powershell 找不到类型 [Windows.UI.Notification]
问题描述
我正在尝试使用 powershell 生成 Windows 10 通知。代码如下:
function Show-Notification {
[cmdletbinding()]
Param (
[string]
$ToastTitle,
[string]
[parameter(ValueFromPipeline)]
$ToastText
)
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$RawXml = [xml] $Template.GetXml()
($RawXml.toast.visual.binding.text|where {$_.id -eq "1"}).AppendChild($RawXml.CreateTextNode($ToastTitle)) > $null
($RawXml.toast.visual.binding.text|where {$_.id -eq "2"}).AppendChild($RawXml.CreateTextNode($ToastText)) > $null
$SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument
$SerializedXml.LoadXml($RawXml.OuterXml)
$Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml)
$Toast.Tag = "PowerShell"
$Toast.Group = "PowerShell"
$Toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1)
$Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell")
$Notifier.Show($Toast);
}
当我运行该函数时,它会抛出如下异常:“无法找到类型 [Windows.UI.Notificaiotn ....” 我认为这是一个 UWP 类,但为什么我无法在 powershell 中访问这个类?
解决方案
推荐阅读
- python - 在 Python 中将文本添加到文件的末尾,但不创建新行
- python - Countif pandas python用于带有通配符的多列
- python - jedi-vim 无法初始化 python
- sql-server - Dapper 查询是否在 QuerySingle 一笔交易中执行?
- sqlite - 当第一个选择查询返回 0 时从第二个选择查询获取结果
- python - 如何让 python 浏览网站并获取有用的数据?
- javascript - 使用 CSS 滚动行为时如何从 URL 中删除#id
- c++ - _wmemcpy 替换 64 位程序
- node.js - 从另一个控制器向控制器发布数据
- reactjs - 在 react-native 中使用导航发送参数