Window Using Code - Maximize doesn't work

Jan 20, 2010 at 11:13 PM

Hi there, in the example this MdiChild cannot be maximised correctly.

Container.Children.Add(new MdiChild()
            {
                Title = "Window Using Code",
                Content = new ExampleControl(),
                Width = 714,
                Height = 734,
                Margin = new Thickness(200, 30, 0, 0)
            });

The MdiChild gets resized to (apparently) the Container size, but it's position is incorrect (origin 200,30). Here are two screenshots (before and after clicking the Maximize button).

http://conceptdevelopment.net/Wpf/Mdi/Before.png

http://conceptdevelopment.net/Wpf/Mdi/After.png

Note that the Maximize button works fine on this MdiChild (ie. with no Content set)

Container.Children.Add(new MdiChild()
            {
                Title = "Empty Window Using Code",
                Icon = new BitmapImage(new Uri("OriginalLogo.png", UriKind.Relative))
            });

Any ideas, hints, tips on where to start looking to fix this would be appreciated.

Jan 26, 2010 at 8:23 PM

Hi, i had the same problem, it seems to be the line Margin=new Thickness(200,30,0,0), i remove that line and it works fine for me.

Feb 19, 2010 at 8:38 PM

Hi

The issue is solved by removing the line Margin = new Thickness(200, 30, 0, 0)

but i have another related problem .. when i give the windowstate Maximized property to the chilld form

like this:

Container.Children.Add(new MdiChild()
            {
                Title = "Window Using Code",
                Content = new ExampleControl(),
               WindowState =WindowState.Maximized ,

            });

It doesnt open in maximised mode...Any thoughts ....how to get child window(which is user control) opened in maximazied state only.

 

Apr 30, 2012 at 8:07 PM
Edited Apr 30, 2012 at 8:09 PM

I know this is technically resurrection, but, I thought the solution problem would be appreciated in case anyone happens along this same issue as I did. I managed to get the window to open in the maximized state by applying "mdiChild.WindowState=Windows.WindowState.Maximized" AFTER "Container.children.add(midChild)." I then had to force the UI to refresh which I did the lazy way by sizing the window. If you wanted to make the window maximized only you could see about setting mdiToShow.MaximizeBox = False to disable the button and then handle all the sizing in code. Not sure if that will work though. The following code is an example of what I have in my project :

    Private Sub btnService_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Dim mdiToShow As MdiChild = New MdiChild
        Dim frmHoldMe As New Frame 'I designed pages and the pages need to be in frames to go into the mdiChild
        frmHoldMe.Content = New ServiceCalls(Me) 'ServiceCalls is the name of the page
        mdiToShow.Content = frmHoldMe
        mdiToShow.Height = 600
        mdiToShow.Width = 600
        mdiToShow.Title = "Service Calls"
        mainDock.Children.Add(mdiToShow)
        mdiToShow.WindowState = Windows.WindowState.Maximized
        Me.Width = Me.Width + 1 'The window opens maximized, however, it takes a refresh to actually work. This will cause that refresh
    End Sub

Jun 10, 2012 at 8:46 AM
Edited Jun 10, 2012 at 8:49 AM

After 2 years of the beginning of the thread I have a stupid solution.

Change this lines

mdiToShow.WindowState = Windows.WindowState.Maximized
Me.Width = Me.Width + 1 'The window opens maximized, however, it takes a refresh to actually

with

            mainDock.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render,
                (RefreshDelegate)delegate { });

            mdiToShow.WindowState = System.Windows.WindowState.Maximized;

and create a delegate like this:

 public delegate void RefreshDelegate();

This is the typical Application.DoEvents(); in .NET 2.0 after you add the mdi child to the container.

Best Regards