Why is this button disabled?

In the following XAML code, the button text is missing. I can change the Margin property, and it becomes obvious that after 250px the content is hidden. Why is this and how can I fix it?

 <Window x:Class="InnerInterface.InventoryManagement" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="someWindow" Height="500" Width="500"> <DockPanel HorizontalAlignment="Left" Name="dockPanel1" VerticalAlignment="Top"> <Grid DockPanel.Dock="Top"> <Button Name="buttonReturnToMainMenu" Content="someButton" Margin="200,0" Width="125" /> </Grid> </DockPanel> </Window> 
+4
source share
3 answers

You have a horizontal edge of 200 and a button width of 125, which means that the total width required for the control to display correctly is about 525.

You also have HorizontalAlignment=Left" on the DockPanel , which means that it will draw content at any desired width and align it on the left side of the screen, rather than stretching it to fill all the free space. This means that it blocks the space by 200 on either side of the control and draws a button in the remaining space.If this remaining space is less than 125, the image will be cropped.

If you switch to HorizontalAlignment="Stretch" , then he first draws the control (with fields) and then stretches its size to fit all available space, so the whole control will be resized, not cropped.

You may be interested in reading this MSDN article on alignment, margins, and padding in WPF.

Edit

If you only want the Left marker to be 200, use Margin="200,0,0,0" . Using Margin="200,0" means that both the left and right margins will be 200.

+15
source

Not quite sure about your specific problem, but maybe this should help:

 <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="500" Width="500"> <DockPanel HorizontalAlignment="Stretch" Name="dockPanel1" VerticalAlignment="Top"> <Grid DockPanel.Dock="Top" > <Button Name="buttonReturnToMainMenu" Content="someButton" Width="125" /> </Grid> </DockPanel> </Window> 
+1
source

The problem is that the Margin button is set as:

 Margin="200,0" 

It should be installed as:

 Margin="200,0,0,0" 

This removes the border on the right side and allows the entire button to be displayed.

+1
source

Source: https://habr.com/ru/post/1400234/