WPF: How can I show my login window (project imported) in front of my application window?

I made a project for a WPF login application, which basically performs a database connection. I am currently developing an application (always in WPF) that needs this login project. I added Login.Exe to the link in my current project, but I can’t find a way to force a start from the login and only after that start my MainWindow ().

I'm trying something like this

namespace Administrator
{ 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Window login = new Login.MainWindow();
            login.Show();
        }
    }
}

My mainwindow.xaml has empty content and this piece of code shows the login form as well as an empty window. How can I achieve my goal?

+4
source share
2

.

App.xaml StartupUri="MainWindow.xaml" Startup="ApplicationStart" App.xaml.cs ApplicationStart.

private void ApplicationStart(object sender, StartupEventArgs e)
{
    Window login = new Login.MainWindow();
    login.Show();

    // Determine if login was successful
    if (login.DataContext is LoginViewModel loginVM)
    {
        if (!loginVM.LoginSuccessful)
        {
            // handle any cleanup and close/shutdown app
        }
    }

    //show your MainWindow
}

, , , DI- ApplicationStart - , , .

+5

App.xaml "ShutdownMode" "StartupUri":

   <Application x:Class="MyApp.App"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:MyApp"
                ShutdownMode="OnExplicitShutdown"
                StartupUri="Login.xaml">

"StartupUri" - .

+6

Source: https://habr.com/ru/post/1675157/


All Articles