I need to 'snap' a WPF window to the left edge of my screen. I've tried setting the Left value to zero, but this leaves a small gap, of about 8 pixels. Does anyone know why/what this is?
It's the window border and its size depends on the current Windows theme so that gap could vary.
Try subtracting the current Non-Client Frame thickness:
myWindow.Left = 0.0 - SystemParameters.WindowNonClientFrameThickness.Left;
Related
I have a winform, I define the Height to be 436 and the Width to be 470. I then display the mouse position in the title bar to check. What I expected to see is a value of 0 to 469 in the X direction when the mouse is over the form. What I see is that the maximum value in this axis is 459 and that the value changes even when the mouse is some distance from the form. I can bodge this to fit but it would be nice to be able to calculate the required size of the form to fit the controls. The height is not correct either. Could anyone point me to an explanation? This is created using VS 2017 on a Windows 10 PC. This is what the screen looks like as the X axis just stops changing, note the mouse position:
enter image description here
Forms have invisible borders. You can use margin instead of exact coordinates
When aligning a WPF window of my application to the left screen border, my code returns negative values for the Left property of the window (-7, not expected).
The same code returns zero on a peer's PC (as expected).
Display scaling is switched off. It is a plain 96 DPI 1920 x 1200 screen.
AFAIR it worked on my PC as expected some time ago and of course I did not change anything ;-)
So
why does WPF return this value and
why does it work differently on different systems and
how can the 'factory settings' be retrieved?
Background: The application supports saving the window positions to a 'workbench' file and loading it again on a different system. This is difficult to achive if (0,0) is not the same on different systems. (Of course the available screens need to be considered. But this is a different stor.y)
Some more wierd details
System.Windows.SystemParameters.WorkArea.TopLeft is (0,0) (as expected).
Other parameters of System.Windows.SystemParameters.WorkArea are also as expected (width and height).
Setting the position of the application window to (-7,0) moves the window to the top left corner of the screen.
After sizing the window to fill the screen (using the mouse) it's width is 1934 (1920 expected). Setting its width to this values resizes the window to fill the screen(width).
So there seems to be some application specific scaling and offset that is consistent in retrieving and setting window size and position but does not match System.Windows.SystemParameters.WorkArea.
As a workaround the following code can be used:
private double GetWindowLeft(Window window)
{
if (window.WindowState == WindowState.Maximized)
{
var leftField = typeof(Window).GetField("_actualLeft", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
return (double)leftField.GetValue(window);
}
else
return window.Left;
}
I'm creating a custom installer and working on the progress bar. I have a timer function that increments the specified rectangle's Height property by +1.
statusBar->Height += 1;
if (statusBar->Height >= 285)
{
StatusBarTimer->Stop();
}
However, the origin point of the shape seems to be located in the top left of the shape, and therefore the Height acts opposite of its controls. I.E. the rectangle extends it's height the opposite direction of where I would like to.
customInstaller
(See arrowed object)
Is there a work-around for this, or better yet, is there a way to change the origin point of an image?
All common modern GUI toolkits position their controls top-down and left-right. The position you specify will be the top-left corner of the control, the size will extend downward and to the right.
If you want a control to grow upward, adjust the top and the height at the same time. Or use an existing progress bar control that supports being vertical.
I come from a WinForms background, so WPF is foreign to me. I am experimenting with it and trying to make a simple Hello World! application, except that the application displays different at runtime than how it is in the designer.
What I mean by that is I have a 'Hello!', and in the designer the location of the button is 12, 12, and and the Window is sized so that is the right/bottom edge of the button is 12, 12 pixels from the right/bottom edges of the window (so there is uniform 12 pixels around the button). When I run the application the button is still 12, 12 pixels from the top & left edges, but is 27, 27 pixels from the right/bottom edges of the Window. I have verified that the button dimensions are correct (I took a screenshot and measured the button in Adobe Photoshop and verified that the button width & height in the XAML code was the same as what was displaying on the screen). The Window is what is growing bigger.
I also verified it was not the canvas getting bigger by explicitly setting the width & height, changing the background color, and setting horizontal/vertical alignment to left/top. So when I ran it again, the canvas stayed the same size, but the Window still had an extra 15 pixels on the right/bottom.
I have tried Googling & searching here for this problem, but can't find an explanation as to why runtime is different from the designer.
I should note I am using Visual 2010, and I am using a simple for the layout.
Anyway, thanks for any clues as to why I am getting 15 extra pixels.
(Note I'd post a screenshot, but as a new user I'm not allowed).
You can use a tool like Snoop to diagnose this. It should allow you to inspect the entire visual tree of your application, and determine which UIElement is responsible for the extra pixels.
I have this panel in my app which is 10400 pixels wide.
I have my CenterOfRotationX and CenterOfRotationZ = 0.5.
I have the GlobalOffsets configured so that the rotation of the panel is visible on the screen.
This video shows the RotationY being set from -180 to 180.
http://www.youtube.com/watch?v=zDrETOueb-w
Its really weird at RotationY = 90 (about 13 seconds on the video), it seems to get stretched to hell when I would expect it to disappear from view.
Also from about 8 - 9 seconds on the video shows the panel starting at RotationY = 0 to RotationY = 20, where it starts to stretch. Over this small rotation it appears to nearly rotate 180 degrees.
Maybe I have some settings wrong but this seems really strange. - The only value changing in this video is the RotationY.
The problem was with the GlobalOffsetX variable on the ProjectionPlane.
This was set to something astronomical so I could see the full rotation on the screen but this had an effect on the rotation.
Setting this to 0 and then moving the Plane to the left using the Canvas.LeftProperty fixed this.