2010-10-20 41 views
2

我正嘗試在powershell中創建一個引用xaml資源內部的程序集文件的包ui。閱讀本post後,我試着這樣做:Powershell包uri對象

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

的我得到一個錯誤,指出因爲有兩個冒號,它期待的端口。

任何人都可以請指教?

+0

很好的問題。如果您嘗試將程序集資源應用於您的窗口,我將http://msdn.microsoft.com/en-us/library/aa970069.aspx中的示例粘貼到C#中也會出現同樣的錯誤 – 2010-10-20 08:53:41

+0

,我認爲您可以添加對dll的引用並在app.xaml中創建一個與此類似的資源字典:; /resource.xaml」/> – foureight84 2010-10-20 09:02:46

回答

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

另一種方式是手工註冊包協議:

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