I've recently been playing around with WPF a little bit. I'm a little confused as my program looks different when it's running from what I created in the designer.
I'm certain that there is a valid reason for this but I can't wrap my head around why something so basic has to be so "mysterious".
To be specific, I mean the bottom and right margin between the button and the inner border of the window.
Designer:
Running program:
Hope someone can help with this.
XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="432,289,0,0"
VerticalAlignment="Top" Width="75" RenderTransformOrigin="-1.387,-0.75"/>
</Grid>
However, some industries still rely on WPF concepts and tools like XAML & MVVM to develop futuristic web, mobile, and desktop applications. None of Microsoft's GUI frameworks ever really die. WPF has top-notch performance, with a high level of customization, and if you aim for Windows, both WPF is critical.
Window is the root control that must be used to hold/host other controls (e.g. Button) as container. Page is a control which can be hosted in other container controls like NavigationWindow or Frame. Page control has its own goal to serve like other controls (e.g. Button). Page is to create browser like applications.
A window is managed by the OS and is placed on the desktop. A UserControl is managed by wpf and is placed in a Window or in another UserControl. Applcations could be created by have a single Window and displaying lots of UserControls in that Window.
But WPF without XAML is possible. You don't even need Visual Studio installed for this, just the . NET CLI and the Developer Command Prompt. Drop these two files in a folder and run msbuild and then you can run the file in the Bin directory.
That's simply because :
Something like this would be very logical:
HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,10,10"
I had this issue as well and found a pretty easy solution for anyone else who runs into this.
SizeToContent
as WidthAndHeight
Presto, the grid is a set size and the window will now size to it, no need to worry about the border or title bar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With