c#:WPF组合 - 如何阻止调整按钮大小
本文关键字:调整 按钮 何阻止 WPF 组合 | 更新日期: 2023-09-27 18:35:34
美好的一天!
如何复合 wpf 窗口-
我有菜单项,一个大文本框和一个按钮。
当用户调整窗口大小时,菜单项应该调整大小,文本框 - 同样的事情,但 Buttn 应该留在原位。
我尝试这样做,但是当用户调整窗口大小时按钮会重新播放或"消失":
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"></ColumnDefinition>
<ColumnDefinition Width="20*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="92*"></RowDefinition>
</Grid.RowDefinitions>
<Menu Grid.Row="0" Grid.ColumnSpan="2" Margin="0,0,10,0" HorizontalAlignment="Stretch">
<MenuItem Header="Settings" Height="24">
<MenuItem Header="Load" Click="MenuItem_Click"/>
<MenuItem Header="Close" Click="MenuItem_Click_1"/>
</MenuItem>
</Menu>
<Grid Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ScrollViewer Margin="0,0,-10,0">
<TextBox HorizontalAlignment="Stretch" Name="tBOutput" TextWrapping="Wrap" AcceptsReturn="True" Text="TextBox" VerticalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
</ScrollViewer>
</Grid>
<Grid Grid.Row="1" Grid.Column="1" ShowGridLines="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="200" MinWidth="100" MaxHeight="500" MaxWidth="200" Margin="5,10,-2,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="13*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*"></RowDefinition>
<RowDefinition Height="80*"></RowDefinition>
</Grid.RowDefinitions>
<Button Name="startBtn" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Start!" Click="startBtn_Click" Margin="10,10,0,0" Grid.ColumnSpan="2" Height="55" Width="90" />
</Grid>
</Grid>
如果我清楚地认出你,你可以尝试这样的事情:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"></ColumnDefinition>
<ColumnDefinition Width="120"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="92*"></RowDefinition>
</Grid.RowDefinitions>
<Menu Grid.Row="0" Grid.ColumnSpan="2" Margin="0,0,10,0" HorizontalAlignment="Stretch">
<MenuItem Header="Settings" Height="24">
<MenuItem Header="Load" />
<MenuItem Header="Close" />
</MenuItem>
</Menu>
<Grid Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ScrollViewer Margin="0,0,-10,0">
<TextBox HorizontalAlignment="Stretch" Name="tBOutput" TextWrapping="Wrap" AcceptsReturn="True" Text="TextBox" VerticalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
</ScrollViewer>
</Grid>
<Grid Grid.Row="1" Grid.Column="1" ShowGridLines="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,10,-2,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="13*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="80*"></RowDefinition>
</Grid.RowDefinitions>
<Button Name="startBtn" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Start!" Margin="10,10,0,0" Grid.ColumnSpan="2" Height="55" Width="90" />
</Grid>
</Grid>