2

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

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

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

有人可以请教吗?

4

1 回答 1

1

您可以选择以下两种方式之一。一种是加载并初始化 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协议:

$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")
于 2010-10-20T14:49:26.413 回答