我正在尝试在 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/