wpf:按钮,文本框,被切断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18086895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:22:53  来源:igfitidea点击:

wpf: Buttons, Textboxes, getting cut off

wpfxaml

提问by AustinT

I am really confused why some of my textboxes and buttons are being cut off, could someone please help me fix this problem? Thanks!!

我真的很困惑为什么我的一些文本框和按钮被切断了,有人可以帮我解决这个问题吗?谢谢!!

XAML CODE

XAML 代码

<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 the textbox is cut off in the corners.
Thank you for the help I appreciate it.

如您所见,按钮和文本框在角落处被切断。
谢谢你的帮助我很感激。

回答by Anand Murali

When you give a Margin value like this Margin="180,10,180,176"then it means that the control has to be placed 180 dip from Left and 10 dip from Top, 180 from Right and 176 from bottom with reference to the parent control. Your controls were clipped because of the high Margin values.

当您提供这样的 Margin 值时,Margin="180,10,180,176"这意味着控件必须相对于父控件放置在距左侧 180 度和距顶部 10 度、距右侧 180 度和距底部 176 度的位置。由于高边距值,您的控件被裁剪。

enter image description here

在此处输入图片说明

Note: dip - device independent pixels.

注意:dip - 设备独立像素。

It is better to create RowDefinitionsfor Gridand place controls in separate rows with reasonable margin value as shown below.

这是更好地创建RowDefinitions用于Grid与合理的余量的值不同的行和位置控制如下所示。

<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>

回答by Reed Copsey

You're explicitly setting a Heightand Widthfor the buttons, but the values you are using are too small.

您正在为按钮明确设置 aHeightWidth,但您使用的值太小。

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 of the layout if you design this yourself using a Gridor other container instead of using Margin, as well.

请注意,如果您自己使用 aGrid或其他容器而不是使用 来设计布局,则可以更好地完成布局Margin

回答by Federico Berasategui

Remove the Height, Widthand Marginproperties.

删除Height,WidthMargin属性。

Don't use the Visual Studio designer to create WPF UIs.

不要使用 Visual Studio 设计器来创建 WPF UI。

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

看看http://wpftutorial.net/LayoutProperties.html

回答by Michael

You have used height, Width property along with Margin property. Remove height and width property and it will work fine. Ex.

您已经使用了高度、宽度属性和边距属性。删除高度和宽度属性,它会正常工作。前任。

<Button Content="Parse" x:Name="btn_parse" Click="buttonParse_Click" Margin="180,10,180,176"/>

<Button Content="Parse" x:Name="btn_parse" Click="buttonParse_Click" Margin="180,10,180,176"/>