Powershell 包 uri 对象

发布于 2024-09-28 09:59:30 字数 238 浏览 0 评论 0原文

我正在尝试创建一个包 ui,引用 powershell 中程序集文件内的 xaml 资源。读完这篇文章后 我尝试这样做:

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

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

有人可以请建议吗?

I'm trying to create a pack ui referencing a xaml resource inside of an assembly file in powershell. After reading this post I tried to do this:

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

The I get an error noting that it is expecting a port since there are two colons.

Can anyone please advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风蛊 2024-10-05 09:59:30

您可以采用以下两种方法之一来解决此问题。一种是加载并初始化 WPF 基础结构:

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

另一种方法是手动注册包协议:

$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")

You can go about this one of two ways. One is to load up and init the WPF infrastructure:

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

The other way is to manually register the 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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文