尊敬的 WPF 和 PowerShell 专业人士,
我正在开发一个 PowerShell (Core, 7) 模块,该模块应具有 WPF GUI。我想以更好的方式组织代码,拆分 XAML,Styles.xaml
例如Colors.xaml
和Templates.xaml
。
代码由多个ps1
文件组成,这些文件在编译期间被组装成一个psm1
模块文件。除了模块文件之外,我psd1
还放置了UI
包含所有xaml
文件的目录:
\_ HIWE (the module)
|_ HIWE.psm1
|_ HIWE.psd1
\_ UI
|_ App.xaml
|_ Colors.xaml
|_ Styles.xaml
\_ Templates.xaml
App.xaml
对同一目录的引用App.xaml
:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml"/>
<ResourceDictionary Source="Styles.xaml"/>
<ResourceDictionary Source="Templates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
问题
因此,作为已安装的模块,根据作为 CurrentUser 或 AllUsers 范围安装,这将最终出现在不同的路径中。
似乎[System.Windows.Markup.XamlReader]::Load($appXmlReader)
不是使用 位置的相对引用,App.xaml
而是使用 执行的 cwd。这就需要以绝对方式放入目录,但由于可能安装到不同的位置,这是不可能的。
这不是需要参考的问题UI\filename.xaml
,这是我已经测试过的。
问题
当您想要有效地拆分 WPF / XAML 代码但又不想得到一个太大的文件时,该如何解决这个问题?