views:

26

answers:

1

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?

+1  A: 

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")
Keith Hill