wpf - Powershell 包 uri 对象

标签 wpf xaml powershell uri pack

我正在尝试在 powershell 的程序集文件中创建一个引用 xaml 资源的包 ui。看完这篇post我试图这样做:

$resource = new-object system.uri("pack://application:,,,/WPFResource;component/test.xaml")

我收到一个错误,指出它需要一个端口,因为有两个冒号。

有人可以请教吗?

最佳答案

您可以选择以下两种方式之一。一种是加载并初始化 WPF 基础结构:

Add-Type -AssemblyName PresentationFramework,PresentationCore
[windows.application]::current > $null # Inits the pack protocol
new-object system.uri("pack://application:,,,/WPFResource;component/test.xaml")

另一种方式是手动注册pack协议(protocol):
$opt = [GenericUriParserOptions]::GenericAuthority
$parser = new-object system.GenericUriParser $opt
if (![UriParser]::IsKnownScheme("pack")) { 
    [UriParser]::Register($parser,"pack",-1) 
}
new-object system.uri("pack://application:,,,/WPFResource;component/test.xaml")

关于wpf - Powershell 包 uri 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3976090/

相关文章:

wpf - 在wpf autocompletebox中,滚动条不会随着向上键移动

.net - WPF(或 WinForm)WebView 无法打开本地 URL(NotFound 404 错误)

c# - 如何从 Xamarin Forms 中的主从页面传递字符串数据

c# - DataTemplate 在 WPF 中传递不正确的命令参数

c# - WPF - 因值更改而触发的常见事件

c# - 一种在关闭上一个窗口的同时打开新窗口的方法

authentication - Powershell BitsTransfer https基本身份验证语法

php - 如何将投票按钮限制为 'To' 地址而不是通过 powershell 在 outlook 中发送到 'Cc'?

wpf - 从 ListView 的 ItemContainer 为 ContextMenu 设置 DataContext?

Powershell 使用远程连接返回不同的信息