Call UserControl from a C# DLL, works not.

Markus Freitag 3,786 Reputation points
2021-07-08T10:41:15.673+00:00

Hello,

how can I call a WPF UserControl from a C#DLL and check the OK event?

With C# WinForms this is possible. Why not with WPF?

 public static void Setup()  
    {  
     Uri iconUri = new Uri(@"test.ico", UriKind.RelativeOrAbsolute);  
      
      
     Window window = new Window  
     {  
     Title = "My User Control Dialog",  
     Content = new UserControlSetup(),  
     ResizeMode = ResizeMode.NoResize,  
     ShowInTaskbar = true,  
     Icon = BitmapFrame.Create(iconUri)  
      
     };  
     bool? ret = window.ShowDialog();  
      
     int z = 0;  
    }  
      
    public static int CallSetupDialog()  
    {  
     //Thread ThreadSetup;  
     //ThreadSetup = new Thread(() => Setup());  
     //ThreadSetup.SetApartmentState(ApartmentState.STA);  
     //ThreadSetup.Start();  
      
     SetupDlg = new frmSetup();   // WinForms looks ok.  
      
      
     SetupDlg.ShowDialog();  
      
      
     return 0;  
    }  
 

  
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,694 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
324 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,484 questions
{count} votes