Click here to Skip to main content
15,902,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I click on maximizebtn_Click and the form is maximized then loadbtn_Click doesn't click


What I have tried:

C#
private void maximizebtn_Click(object sender, RoutedEventArgs e)
        {
            // Set the window state to maximized
            if (WindowState == System.Windows.WindowState.Normal)
            {
                WindowState = System.Windows.WindowState.Maximized;
            }
            else
            {
                WindowState = System.Windows.WindowState.Normal;
            }
        }
		
private void loadbtn_Click(object sender, RoutedEventArgs e)
    {
        // Create OpenFileDialog
        Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

        // Set filter for file extension and default file extension
        dlg.DefaultExt = ".stl";
        dlg.Filter = "STL Files|*.stl;";

        // Display OpenFileDialog by calling ShowDialog method
        Nullable<bool> result = dlg.ShowDialog();

        if (result == true)
        {
            // Open document
            string filename = dlg.FileName;
            openfile = filename;
        }
        ModelVisual3D device3D = new ModelVisual3D();
        device3D.Content = Display3d(openfile);
	//Add the ModelVisual3D to the Children property of the HelixViewport3D
        viewPort3d.Children.Add(device3D);
    }
Posted
Updated 15-May-23 14:22pm
Comments
Richard Deeming 15-May-23 6:09am    
That seems extremely unlikely. I've never seen a WPF application stop firing events when the window is maximized.

Set a breakpoint of the first line of the loadbtn_Click event handler - you'll probably find that the event is being fired, but something else is going wrong. Perhaps the dialog is appearing behind your window?

If it's definitely not hitting the event handler, then there's something else going on. We'll need to see the relevant parts of your XAML.

1 solution

Make sure that you pass the owning window, without it, it may be displaying behind your app maximized window. See: ShowDialog(Window) - Microsoft Learn[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900