I've got a simple WPF application with the usual static Main() (entry point to application). Main will do some initialisation stuff before the UI is displayed. It will then creating and run the start-up Window. However, what I need to do is pass a custom object from main to start-up Window but I'm not sure how to do it.
My main class containing Main() looks like this:
class App : Application
{
[STAThread()]
static void Main()
{
MyObject obj;
// Some processing stuff here.
new App(obj);
}
public App(MyObject obj)
{
StartupUri = new System.Uri("MainWindow.xaml", UriKind.Relative);
Run();
}
}
Obviously, MyObject
is my custom object that I would like to have access to in my start-up Window. How can I do this?
TIA
Add a parameter of type MyObject
to your MainWindow
constructor (or a property if your prefer), then create your window manually. Simply use the overload of Run
that takes a Window
parameter rather than using a startup URI to show this window as the main window.
Run(new MainWindow(obj));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With