admin管理员组

文章数量:1125586

I am trying to implement a loading window to my WPF project, but running into an issue with hiding it after first use and then showing it again when needed. The window works fine after first Show(), after Hide() and second Show(), the window is completely blank and nothing is showed. After all work is done, the loading window then loads its contents, but at this point the loading job is already done and I want to hide the window again. Could this be an threading issue, what am I missing? I am confused, because after the first show everything is fine...

The App.xaml.cs looks like this, comments showing what i want to do at certain steps:


namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var _Window = new LoadingWindow();
            // Everything fine here
            _Window.Show();
            // Do Loading work here
            // Hide Window to show AuthenticationWindow
            _Window.Hide();
            // Ask for password here
            // Loading Window doesn't show image and is completely blank
            _Window.Show();
// Do some other loading before showing MainWindow
            _Window.Hide();
        }
    }
}

The app.xaml looks like this:


<Application x:Class="WpfApp1.App"
             xmlns=";
             xmlns:x=";
             xmlns:local="clr-namespace:WpfApp1"
             Startup="Application_Startup">
    <Application.Resources>
         
    </Application.Resources>
</Application>

Loading window looks like this:

using System.Windows;

namespace WpfApp1
{
    /// <summary>
    /// Interaktionslogik für LoadingWindow.xaml
    /// </summary>

    public partial class LoadingWindow : Window
    {
        public LoadingWindow()
        {
            InitializeComponent();
        }
    }
}

And its XAML:

<Window x:Class="WpfApp1.LoadingWindow"
        xmlns=";
        xmlns:x=";
        xmlns:d=";
        xmlns:mc=";
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="LoadingWindow" Height="450" Width="800" Topmost="True">
    <Grid>
        <Image Source="/Icons/windows.png"></Image>
    </Grid>
</Window>

The image showed inside the loading window has the following properties: Properties windows.png

本文标签: C WPF Window shows nothing after Hide()Stack Overflow