.NET Core Window not showing correct content

Paul C 0 Reputation points
2025-11-05T15:18:49.3366667+00:00

I've created a WPF application targeting .NET core. I have a GUI defined in a file named MainWindow.xaml The Main window displays fine when the program is executed. When the GUI runs there's, a button named "About". When the "About" button is clicked a new Window, named About is launched. The window launches fine but there's a big problem that I cannot figure out.

The About Window is described in a "About.xml" file - with text, and graphic objects that need to be shown when the window is launched. When the "About" button is clicked (MainWindow) I have a binding to a file named "ViewModelAdditionalInfo.cs" which calls a function "OnAboutSelected()"

This is what the "OnAboutSelected()" function looks like,

private void OnAboutSelected()

{

// Ensure execution on the UI thread

Application.Current.Dispatcher.Invoke(() =>

{

    AboutPage aboutWindow = new AboutPage();    

   aboutWindow.ShowDialog();

});

}

Note: aboutWindow.ShowDiaglog() launches a new window defined in file "About.xaml" The problem is that the call to "aboutWindow.ShowDialog()" does NOT show any content that's defined in the "About.xaml" file - I only get a blank window showing no content. I've asked GitHub Copilot for suggestions, and it has stated everything looks right. The only thing I can think of is that I'm trying to open the new window (aboutWindow) on a thread that's not the same thread the MainWindow is running on. If you look at the code in function OnAboutSelcted() the Dispather.Invoke should make sure that the abouWindow is being launched on the same thread as the MwainWindow. Any ideas as to what I'm doing wrong would be greatly appreciated. Thanks.

Developer technologies | .NET | Other
{count} votes

3 answers

Sort by: Most helpful
  1. Adiba Khan 1,440 Reputation points Microsoft External Staff
    2025-11-06T12:03:09.4966667+00:00

    Thank you for reaching out. This behavior typically occurs when the about window (or page) is being created on a non-UI thread or when it's being instantiated as the wrong type (page instead of window)

    In WPF, only the main UI thread has access to visual and dependency objects (XAML elements). If the ShowDialog() or Show () call is invoked from another thread, the content may not render properly- resulting in an empty or blank window.

    Resolution Steps

    1.      Ensure the about window is defined as a window.

    • Confirm that your About.xaml file begins with:
    <Window x:Class=”YourAppNameSpace.About”
    Xmlns=”
    Xmlns= 
    Title=”About” Height=”300” Width=”400”>
    
    
    
    • If it starts with <Page> instead of <Window>, you will need to host it within a window to show it usingShowDialog():
    Window aboutWindoe=new Window
    {
                    
                    
    };
    aboutWindow.ShowDialog();
     
    
    
    

    **2.      **Run window creation on the main UI dispatcher

    make sure you create and show the new window on the UI thread:

    private void OnAboutSelected()
    {
                    
                    
    					Var aboutWindow = new About();
    					AboutWindow.Owner = Application.Current.MainWindow;
    					aboutWindow.ShowDialog();
    				});
                    
    
    
    

    **3.      **Check build option and namespace

    • right click on About.xaml-> properties insure build action= Page and Custom Tool=MSBuild:Complie.
    • Verify the namespace in your About.xaml.cs matches your project structure.

    **4.      **Avoid creating UI elements in background threads

    if you are calling OnAboutSelected() show an asynchronous background operation, ensure it Marshals back to the UI thread using Dispatcher.Invoke() before interacting with UI components.

    Additional Diagnostic Step

    If the issue persists, test by directly launching the About window from MainWindow:

    Var aboutWindow = new About();
    aboutWindow.ShowDialog();
    

    if this works correctly, it confirms that the issue lies with cross thread UI access.

    References:

    Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".


  2. Paul C 0 Reputation points
    2025-11-14T15:44:24.9733333+00:00

    How can I upload my project? It's greater than 3Mb in size? I cannot give you a GitHub link because the GitHub repo is a private GitHub repo?

    0 comments No comments

  3. Paul C 0 Reputation points
    2025-11-14T16:10:39.4233333+00:00

    A thousand "Thank yous" for helping me. It finally works. I'm able to see the About Page now.

    When I update my project file with this information

    "<ItemGroup> <Page Include="VIEW/About.xaml"> <Generator>MSBuild:Compile</Generatoe> ` </Page> <Compile Include="VIEW\About.xaml.cs" DeependsOn="Compile:VIEW\About.xaml"> <DeependentUpon>About.xaml</DependentUpon> </Compile> </ItemGroup>"

    It worked fine. Last Question. Why did I have to do this manually? Why didn't VS2022 do this for me automatically? Will I have the same issue if I try to add a new Window in the future? Anyway many, many thanks for the help.

    Cheers,

    Paul


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.