The Wpf dll user control window does not appear when called from an exe application

advertisements

I have a WPF Menu application wich calls a WPF User Control dll and the dll window is not showing. The dll does not require parameters and its window have only one button. I added a MessageBox to the dll code to check if it is being loaded and it does, but the window does not show.

I'm using VS 2015. The dll project named Empresa.Reg was created using C# Windows Classic Desktop WPF User Control (There is no C# Windows WPF User Control selection), it is referenced in the Menu project and its ouput is Class Library. Menu project named MenuDePruebas Ouput is Windows Application. Any help would be appreciated.

This is the Menu exe code:

....

using System.Windows;
using Empresa.Reg;

namespace MenuDePruebas

{
   public partial class MainWindow : Window

{
    public MainWindow()
    {
        InitializeComponent();
    }
    private void BtnRegEmpresa_Click(object sender, RoutedEventArgs e)
    {
        UserControl1 algo = new UserControl1();
    }
}

}

And this is the WPF User Control dll code:

....

using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Empresa.Reg
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>

public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
        MessageBox.Show("Testing");  // This line works as expected

    }
    private void button_Click(object sender, RoutedEventArgs e)
    {

    }
}

}


I think I've found a solution creating a new window for the dll user control in the menu exe as follows, something I thought was an automatic thing. If there is a better solution I appreciate letting me know. Thanks.

private void BtnRegEmpresa_Click(object sender, RoutedEventArgs e)
    {
        Window UserControlNewWindow = new Window
            {
            Title = "Some Title", Content = new UserControl1()
            };

        UserControlNewWindow.ShowDialog();
    }