How do you calculate the offset to the client area in WPF?
Posted
by chris
on Stack Overflow
See other posts from Stack Overflow
or by chris
Published on 2010-01-08T09:03:34Z
Indexed on
2010/03/12
5:07 UTC
Read the original article
Hit count: 195
I want to position a modal dialog (progress window) at the top right corner of the parent window client area.
This code will put it in the corner of the non-client area, but how do I calculate the offset to the client area?
this.Owner=owner;
this.Left=owner.Left+owner.ActualWidth-Width;
this.Top=owner.Top;
Edit:
I found this 'solution' that works for normal windows:
this.Left=owner.Left+owner.ActualWidth-Width-SystemParameters.ResizeFrameVerticalBorderWidth;
this.Top=owner.Top+SystemParameters.ResizeFrameHorizontalBorderHeight+SystemParameters.WindowCaptionHeight;
This would however fail for windows that have customized borders.
EDIT:
The code should work regardless of the systems DPI setting (e.g. 120 instead of 96).
© Stack Overflow or respective owner