Wpf: buttons, text fields, cropping

I'm really confused why some of my text fields and buttons are disabled, can someone please help me fix this problem? Thank you !!

XAML CODE

<Grid> <TabControl> <TabItem Name="tabHome"> <TabItem.Header> <Label Content="Home" MouseLeftButtonDown="tabHome_Click"/> </TabItem.Header> <Grid> <Button Content="Parse" Height="23" x:Name="btn_parse" Width="75" Click="buttonParse_Click" Margin="180,10,180,176"/> <TextBox IsReadOnly="True" x:Name="txtbox_filepath" Height="25" Width="135" Margin="151,52,150,132" /> <Button Content="Reset" Height="23" x:Name="btn_reset" Width="75" Margin="180,122,180,64" Click="buttonReset_Click"/> </Grid> </TabItem> <TabItem Name="tabConfig"> <TabItem.Header> <Label Content="Configuration" MouseLeftButtonDown="tabConfig_Click"/> </TabItem.Header> <ScrollViewer> <StackPanel Name="panelConfig"> </StackPanel> </ScrollViewer> </TabItem> <Grid> 

Screenshot

screenshot

As you can see, the button and text box are cropped at the corners.
Thanks for the help I appreciate.

+6
source share
3 answers

When you give a Margin value like this Margin="180,10,180,176" , it means that the control should be placed 180 degrees to the left and 10 dip to the top, 180 to the right and 176 from the bottom with a link to the parent control. Your controls have been trimmed due to high Margin values.

enter image description here

Note: independent pixel devices.

It is better to create RowDefinitions for the Grid and place the controls in separate rows with a reasonable field value, as shown below.

 <Grid> <TabControl> <TabItem Name="tabHome"> <TabItem.Header> <Label Content="Home"/> </TabItem.Header> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Button Grid.Row="0" Content="Parse" Height="23" x:Name="btn_parse" Width="75" Margin="10" /> <TextBox Grid.Row="1" IsReadOnly="True" x:Name="txtbox_filepath" Height="25" Width="135" Margin="10" /> <Button Grid.Row="2" Content="Reset" Height="23" x:Name="btn_reset" Width="75" Margin="10"/> </Grid> </TabItem> <TabItem Name="tabConfig"> <TabItem.Header> <Label Content="Configuration"/> </TabItem.Header> <ScrollViewer> <StackPanel Name="panelConfig"> </StackPanel> </ScrollViewer> </TabItem> </TabControl> </Grid> 
+9
source

You explicitly set the Height and Width buttons for the buttons, but the values ​​you use are too small.

If you leave them off, the button should display correctly:

 <Button Content="Parse" x:Name="btn_parse" Click="buttonParse_Click" Margin="180,10,180,176"/> <Button Content="Reset" x:Name="btn_reset" Margin="180,122,180,64" Click="buttonReset_Click"/> 

Note that you can do a better job with the layout if you do it yourself using a Grid or another container instead of using Margin .

+3
source

Remove the Height , Width and Margin properties.

Do not use the Visual Studio Designer to create WPF user interfaces.

Take a look at http://wpftutorial.net/LayoutProperties.html

0
source

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


All Articles