1

So I have a WPF application that maximizes window when it's dragged to the top of the screen.

However, I'd like to change a property, and because of that I think it would be best If I create my own drag maximize properties.

What's the easiest way to do that?

Thanks in advance.

user3410566
  • 45
  • 2
  • 15
  • so what you want? stop maximizing the windows when reached top? – mfs Nov 28 '14 at 17:10
  • No. It does that. I just want it to change a text in the XAML code when it does. – user3410566 Nov 28 '14 at 17:58
  • can't you do it below the code where you are manually re-sizing the window – mfs Nov 28 '14 at 17:59
  • Maybe I did not explain as I should. The problem is that the maximized window Icon on the titlebar is not changed if the window is dragged. If I use the maximize button it does. Otherwise it stays the same, and it annoys the s@%#t out of me. :) – user3410566 Nov 28 '14 at 18:24

1 Answers1

1

You can check if the WindowState of your window is set to "Maximized". If it is maximized, you can change the text accordingly.

For this, you need to subscribe to the SizeChanged event of the window, and in the event handler, check if the WindowState is set to Maximized/Normal. If so, you can change the text accordingly.

I'm assuming that you're using a custom window trying to denote the minimize, restore and close buttons using buttons with font "Wingdings" or some such font which has glyphs to denote the icons for minimize, restore/maximize, and close.

Anyway, even if my assumption is wrong, you can always adapt the code below as per your situation.

    public CustomWindow()
    {
        SizeChanged += CustomWindow_SizeChanged;
    }

    void CustomWindow_SizeChanged(object sender, SizeChangedEventArgs e)
    {
         CheckRestoreButtonIcon();
    }

    protected void CheckRestoreButtonIcon()
    {          
        //i'm assuming that the button is named as restoreButton.
        //in wingdings, 1 is for maximized glyph, 2 is for restore glyph
        // you can always set content to whatever you want!

        if (restoreButton == null)
            return;

        if (WindowState == WindowState.Maximized)
            restoreButton.Content = "1"; //maximizee glyph
        else
            restoreButton.Content = "2";//restore glyph
    }
Bharat Mallapur
  • 674
  • 9
  • 17
  • 1
    Also, please note that this effect of maximizing upon being dragged to top of screen is not present in all windows operating systems. It is a feature called Aero Snap present in Windows 7 onwards. http://windows.microsoft.com/en-IN/windows7/products/features/snap – Bharat Mallapur Jan 22 '15 at 09:24