【发布时间】:2018-11-21 09:40:14
【问题描述】:
我已将我的 WPF 项目集成到一个混合解决方案中。该解决方案有 3 个用 WinForms (.cs) 编写的项目,1 个用 WinForms (.vb) 编写的项目,还有一个用 WPF 编写的项目(使用 MahApps)。 我的项目/窗口的所有者必须是用 WinForm 编写的三个之一。
我打过这样的电话:
using WPFSolution;
using System.Windows.Forms.Integration;
private void buttonOpenWPFUi_Click(object sender, EventArgs e)
{
var pm = new ProductsMenu();
ElementHost.EnableModelessKeyboardInterop(pm);
pm.Show();
}
ProductsMenu是我在App.xaml上的起点
但是当我到达ProductsMenu.xaml.cs 的InitializeComponents() 时,System.Windows.Markup.XamlParseException 被抛出
错误是:IOException: Cannot locate resource 'resources/icons.xaml'。
我的 App.xaml 文件:
<Application x:Class="WPFSolution.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="ProductsMenu.xaml" ShutdownMode="OnMainWindowClose">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Red.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<!-- BaseDark.xaml | BaseLight.xaml -->
<!-- Icons -->
<ResourceDictionary Source="pack://application:,,,/WPFSolution;component/Resources/Icons.xaml"></ResourceDictionary>
<!-- Languages -->
<!--<ResourceDictionary Source="Resources/StringResources.en.xaml"></ResourceDictionary>-->
<ResourceDictionary Source="Resources/StringResources.it.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type ToolTip}">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="7,4,7,4"/>
</Style>
<!--IMMAGINI -->
<!--nodi-->
<!--<BitmapImage x:Key="Nodo1" UriSource="Resources/img/TileImages/nodi/nodo1.jpg"></BitmapImage>
<BitmapImage x:Key="Nodo2" UriSource="Resources/img/TileImages/nodi/nodo2.jpg"></BitmapImage>
<BitmapImage x:Key="Nodo3" UriSource="Resources/img/TileImages/nodi/nodo3.jpg"></BitmapImage>
<BitmapImage x:Key="Nodo4" UriSource="Resources/img/TileImages/nodi/nodo4.jpg"></BitmapImage>-->
</ResourceDictionary>
</Application.Resources>
我尝试将 Icons.xaml/Build Action 设置为资源和页面。 我错过了什么?
【问题讨论】:
-
WPFSolution是包含 Icons.xaml 的程序集的名称吗? -
是的,它是包含文件的程序集。如果我将 WPF 解决方案作为独立模块运行,一切正常。
-
应用程序项目是否引用了该程序集?
-
是的,我在下面添加了引用:解决方案资源管理器 > MainProject > 引用 > 右键单击 > 添加引用... > 项目 > WPFSolution... 然后我检查了整个解决方案是否具有相同的.NET 框架版本 (4.6.1)
标签: c# wpf winforms mahapps.metro