【发布时间】:2014-11-17 04:14:38
【问题描述】:
我在一个解决方案中有一个 Winforms 项目和多个 WPF 项目。我想从 Winform 应用程序中打开一个 WPF 窗口(如果重要的话,它是来自 Mahapps 的 MetroWindow)。
在查看this stackoverflow question 接受的答案后,我最终得到了这段代码:
OpenWPFAppButton_Click(object sender, EventArgs e)
{
WPFApp wpfApp = new WPFApp();
ElementHost.EnableModelessKeyboardInterop(wpfApp);
wpfApp.Show();
}
不幸的是,如果我单击该按钮,则会发生 XamlParseException,它指向 WPFApp.xaml(主 Xaml 文件)中的第一行 Style="{StaticResource ... }"。
这是否意味着我无法从包含静态资源的 Winforms 打开 WPF Windows?还是我在这里遗漏了一些简单的东西?
编辑:这是 App.xaml 文件的内容:
<Application x:Class="WPFAppProjectName.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
StartupUri="WPFApp.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/ButtonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/MenuStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/TextBoxStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
【问题讨论】: