如果我最大化或最小化窗口,如何让WPF应用程序的xaml文件中的菜单栏自动调整大小?
以下是代码:
<Window x:Class="Interface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Physiosoft" Height="750" Width="1100">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Menu Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Height="23" HorizontalAlignment="Left" Name="menu1" VerticalAlignment="Top" Width="1088" MinHeight="23" MinWidth="1088">
<MenuItem Header="File">
<MenuItem Header="Save Ctrl + S" />
</MenuItem>
<MenuItem Header="Help">
<MenuItem Header="About Physiosoft F1" />
</MenuItem>
</Menu>
</Grid>
答案 0 :(得分:2)
要么在DockPanel内使用其对接属性填充(by, precisely not setting it),要么在Grid列/行中使用,其宽度/高度设置为*
所以它会自动调整到可用空间。
例如,这将创建一个带有主面板和可调整大小菜单的三列布局,并将其用作起点:
<Window x:Class="Interface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Physiosoft" Height="750" Width="1100">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Menu Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Name="menu1">
<MenuItem Header="File">
<MenuItem Header="Save Ctrl + S" />
</MenuItem>
<MenuItem Header="Help">
<MenuItem Header="About Physiosoft F1" />
</MenuItem>
</Menu>
</Grid>