I have a WPF project using a lot of Resource Dictionaries and Entity Framework connected to a local database. Everything is working fine when I am testing the project in a separate Solution.
Now, I am trying to connect this WPF project to an existing Excel VSTO project and run the WPF application window by clicking on a button on Excel Ribbon. I have modified App.xaml.cs as following:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
MainWindow view = new MainWindow();
view.Show();
}
}
Also, I’ve removed the StartupUri="MainWindow.xaml" from App.xaml. On the Excel Ribbon I have a button that supposed to run the application:
private void button1_Click(object sender, RibbonControlEventArgs e)
{
App application = new App();
application.Run();
}
Now I have two separate problems:
First, when I click the button I get exceptions on a different parts of the MainWindow.xaml like this: “Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception”. Most likely the connection to the resources is missing.
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator"/>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionaries\DataGridDictionary.xaml" />
<ResourceDictionary Source="Dictionaries\DarkTheme.xaml" />
<ResourceDictionary Source="Dictionaries\WindowStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
I have tried to repeat the same procedure with an empty WPF window and it works, but now I am running to a second issue. When I click again on the button I get the exception; “Cannot create more than one System.Windows.Application instance in the same AppDomain.”
I think in a large project it is normal to have several modules, each one as a WPF window and these WPF windows to be called from the Main application - Windows form or Office Ribbon.
Could you please suggest how to fix both issues above? Thank you!
Edit: I don’t want to use Task Pane and hosting WPF controls. I prefer to run WPF application as a separate window independent from Excel.