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")
精彩评论