Amir Astaneh
Amir Astaneh

Reputation: 2206

Find Docking a Window to Left/Right Side

Is there any way to find out an EVENT (or property or method or something like) for detect Window Docking to Left or Right Side?

Description:

Question:

I need to have some changes in my window after docking to left or right. I need one trigger in WPF/XAML but i can't find any property or event related to Docking to left/right.

Upvotes: 4

Views: 2170

Answers (3)

zORg Alex
zORg Alex

Reputation: 381

I did this around my window in it's Template:

<Border BorderBrush="Transparent" BorderThickness="5" Margin="-5"
        Effect="{DynamicResource ShadowEffect}">
  <...>
</Border>

Negative margin negates border thickness.

Upvotes: 0

Michael
Michael

Reputation: 396

In the SizeChanged event you can detect if the window is docked with:

bool isDocked = 
     window.WindowState == WindowState.Normal &&
     window.Width != window.RestoreBounds.Width &&
     window.Height != window.RestoreBounds.Height

at least, this is a pretty good indicator.

Upvotes: 1

Anton Tykhyy
Anton Tykhyy

Reputation: 20076

There isn't any special event because 'docking' to left/right is not a special operation like minimize/maximize, merely a particular way of repositioning of the window. The user can mimic 'docking' exactly by restoring, moving and resizing the window. Therefore, your UI logic appears questionable. Imagine the user restoring the window and then resizing it so that it fills approximately half a screen close to the right edge of the screen. What should happen?

Protip: there may be multiple monitors and your window may straddle them.

Upvotes: 1

Related Questions