I have created two buttons using the following XAML
code.
<Button x:Name="Button1" Width="100" Content="Button1" HorizontalAlignment="Left" VerticalAlignment="Top" ></Button> <Button x:Name="Button2" Width="100" Content="Button2" HorizontalAlignment="Left" VerticalAlignment="Top" ></Button>
The two buttons are tightly touching each other. How to put some space between them?
Note: The buttons are located inside a stackpanel with Horizontal orientation.
If you do not use (for some reason) Button's Margin property, you can put transparent Separator (Transparent background color) with desired Width (or/and Height) between your controls (Buttons in your case).
There are several techniques for preserving white space in the source XAML for eventual presentation that are not affected by XAML processor white-space normalization. xml:space="preserve": Specify this attribute at the level of the element where white-space preservation is desired.
Padding represents the distance between the side of the control (which can be the margin) and its content. The content depends on the type of the control. Margin is outside the UI element, while Padding is inside it.
The Viewbox control is used to stretch or scale a child element.
If you do not use (for some reason) Button's Margin property, you can put transparent Separator (Transparent background color) with desired Width (or/and Height) between your controls (Buttons in your case).
In xaml:
<StackPanel Orientation="Horizontal"> <Button x:Name="Button1" Width="100" Content="Button1"/> <Separator Width="20" Background="Transparent"/> <Button x:Name="Button2" Width="100" Content="Button2"/> </StackPanel>
Add a Margin to your buttons
<Button Margin="10" x:Name="Button1" Width="100" Content="Button1" HorizontalAlignment="Left" VerticalAlignment="Top" ></Button> <Button Margin="10" x:Name="Button2" Width="100" Content="Button2" HorizontalAlignment="Left" VerticalAlignment="Top" ></Button>
The Margin will make sure there is at least that much space between each button and any other control
Something you might find useful is that you can have different margin values for top, left, right and bottom so:
Margin="10,0,10,0"
Would space the buttons out horizontally but wouldn't make them any smaller vertically...
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