wpf:按钮、文本框、被切断
我真的很困惑为什么我的一些文本框和按钮被切断了,有人能帮我解决这个问题吗?谢谢wpf:按钮、文本框、被切断,wpf,xaml,Wpf,Xaml,我真的很困惑为什么我的一些文本框和按钮被切断了,有人能帮我解决这个问题吗?谢谢 XAML代码 <Grid> <TabControl> <TabItem Name="tabHome"> <TabItem.Header> <Label Content="Home" MouseLeftButtonDown="tabHome_Click
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>
屏幕截图
正如你所看到的,按钮和文本框在角落里被切掉了。
感谢您的帮助,非常感谢。删除
高度
、宽度
和边距
属性
不要使用VisualStudio设计器创建WPF UI
看看您正在为按钮显式设置一个
高度
和宽度
,但是您使用的值太小了
如果将其禁用,则按钮应正确显示:
<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"/>
请注意,如果您自己使用
网格或其他容器而不是使用边距,那么您可以更好地设计布局。当您给出这样的边距值Margin=“180,10180176”
时,这意味着控件必须从左侧倾斜180度,从顶部倾斜10度,参照父控件,从右侧180,从底部176。您的控件由于高边距值而被剪裁
注:dip-设备独立像素
最好为网格
创建行定义
,并将控件放置在具有合理边距值的单独行中,如下所示
<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>
您使用了高度、宽度属性和边距属性。删除“高度”和“宽度”属性,它将正常工作。前
@ReedCopsey这正是我要说的。谢谢你,我接受了你的建议,现在我该如何在按钮和文本框之间设置间距?请给出一个合理的边距值,如5或10。检查我的最新答案。