开发者

Powershell pack uri object

开发者 https://www.devze.com 2023-01-20 18:47 出处:网络
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:

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 pl开发者_C百科ease advice?


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

精彩评论

暂无评论...
验证码 换一张
取 消