2

In both Window Forms and WPF there is this .WindowState which I can set to

Minimized, maximized or Normal

I wonder if there is anything similar already implemented for docking the window to the left/right sides of the screen like with the Win + <- / -> keys for Windows 7/8?

I've googled and it seems people call Win32 APIs and implement this on their own

Am I supposed to write a custom docking code or is there a simple flag I can set somewhere like the WindowState ?

TFD
  • 23,890
  • 2
  • 34
  • 51
Banana
  • 7,424
  • 3
  • 22
  • 43

1 Answers1

4

No, there isn't a flag that you can set. Windows changes the rectangle of the window, and the WPF Window has no knowledge of what is happening except that the rectangle has changed.

It is quite simple to change the rectangle on your own. (Actually replacing the functionality of Windows is a bit more challenging.)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace StackOverflowWPF
{
   /// <summary>
   /// Interaction logic for MainWindow.xaml
   /// </summary>
   public partial class MainWindow : Window
   {
      public MainWindow()
      {
         InitializeComponent();
      }

      private void Button_Click_1(object sender, RoutedEventArgs e)
      {
         this.Top = 0;
         this.Left = 0;
         System.Drawing.Rectangle screenBounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
         this.Width = screenBounds.Width / 2;
         this.Height = screenBounds.Height;
      }
   }
}
LVBen
  • 2,041
  • 13
  • 27
  • Window maximized state is more than just different bounds. – Banana May 17 '14 at 19:35
  • Not from the point of view of the WPF window. Windows tracks the rectangles on its own. The WPF Window has no knowledge of what is happening except that the rectangle has changed. – LVBen May 17 '14 at 19:44
  • I improved my answer a bit based on what @Banana said. – LVBen May 17 '14 at 19:48