溢出社区, 我的控件大小有问题(更具体:按钮) 背景故事: 我正在使用一个程序,要求您连接到特定的网站(通过我的计算机上的程序托管)。我想使用Microsoft Visual Studio中的WPF c#Web浏览器工具,而不是打开我首选的Web浏览器。 现在: 我已经做到了这一点,因此当调整窗口大小时,Web浏览器工具可以调整大小,但调整大小会影响按钮(总共2个)。按钮变小但它们只增长到设定尺寸(如设计师所做)。 XAML视图:
<Window x:Name="PhantomBot_Browser" x:Class="PhantomBot_Browser_.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PhantomBot_Browser_"
mc:Ignorable="d"
ResizeMode="CanResize"
Title="PhantomBot Browser" Height="446.079" Width="731.863">
<Grid>
<Grid x:Name="grid1" HorizontalAlignment="Left" VerticalAlignment="Top" Height="auto" Width="auto" >
<Grid Margin="0,35,0,0">
<Border HorizontalAlignment="Left" Width="auto" Height="auto">
<WebBrowser x:Name="webbrowser1" ClipToBounds="True" Height="auto" Width="auto" />
</Border>
</Grid>
<Grid Margin="10,10,663,385">
<Button x:Name="refresh_button" Content="Refresh" HorizontalAlignment="Left" VerticalAlignment="Top" Width="auto" Height="auto" Click="refresh_button_Click"/>
</Grid>
<Grid Margin="66,10,624,385">
<Button x:Name="gobutton" Content="GO" HorizontalAlignment="Left" VerticalAlignment="Top" Width="auto" Height="auto" Click="gobutton_Click"/>
</Grid>
</Grid>
</Grid>
MainWindow.xaml.cs视图:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void gobutton_Click(object sender, RoutedEventArgs e)
{
webbrowser1.Navigate("http://localhost:25005/panel");
}
private void refresh_button_Click(object sender, RoutedEventArgs e)
{
webbrowser1.Refresh();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
//Grid.Width = this.ActualWidth; Remove the two slashes at the front and minus/add values ONLY if you need it.
grid1.Height = e.NewSize.Height - 100;
grid1.Width = e.NewSize.Width - 300;
webbrowser1.Height = grid1.Height - 300;
//refresh_button.Width = 51;
//gobutton.Width = 34;
}
}
我希望按钮保持在他们的位置和尺寸。
更新 :(部分图片) 程序尺寸较小时的图片(查看左上角的按钮!) https://i.stack.imgur.com/OZa0r.png
当程序尺寸更大时图片(按钮没问题) https://i.stack.imgur.com/LT3yd.png
不介意连接错误,故意
答案 0 :(得分:-1)
网格101:支持添加行和列并为每个设置高度/宽度,可以相对于包含元素,也可以是固定的。 例如:
<Grid>
<Grid.RowDefintions>
<RowDefintion Height="Auto"/> Will receive height per child in that row.
<RowDefintion Height="5"/> Height is 5 pixels
<RowDefinition Height=""/> Height is remaining space (Height in this case)
<RowDefintion Height="2"/> Height is twice the height the preceeding row
</Grid.RowDefintions>
</Grid>