我设置了窗口属性ResizeMode="CanResize", WindowStyle="None"
,
但是当WindowState="Maximized"
时,左侧显示不完整。
很奇怪。
<Window x:Class="WpfApp24.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:WpfApp24"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
AllowsTransparency="True"
WindowStartupLocation="CenterScreen"
WindowState="Maximized"
ResizeMode="CanResize"
WindowStyle="None"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="38"/>
<RowDefinition Height="*"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBlock Text="navBarGroup1" Grid.Row="1" Grid.Column="0"/>
</Grid>
</Window>
C# code
public MainWindow()
{
InitializeComponent();
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
答案 0 :(得分:0)
当您拥有WindowState="Maximized"
和WindowStyle="None"
时,该窗口在屏幕的各个边上延伸超出屏幕的实际边缘几个像素。当最大化时,Windows会修剪窗口的边缘以遮盖通常是调整大小的边缘。
由于您希望最大化窗口并删除样式,因此属性ResizeMode="CanResize"
是无用的。
如果您这样设置属性,它将解决您的问题:
ResizeMode="NoResize"
xaml的完整代码:
<Window x:Class="WpfApp24.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:WpfApp24"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
AllowsTransparency="True"
WindowStartupLocation="CenterScreen"
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="38"/>
<RowDefinition Height="*"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBlock Text="navBarGroup1" Grid.Row="1" Grid.Column="0"/>
</Grid>
</Window>
在网格中留出6个边距,以防止元素掉到边缘:
<Grid Margin="6">
完整代码:
<Window x:Class="WpfApp24.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:WpfApp24"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
AllowsTransparency="True"
WindowStartupLocation="CenterScreen"
WindowState="Maximized"
ResizeMode="CanResize"
WindowStyle="None"
>
<Grid Margin="6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="38"/>
<RowDefinition Height="*"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBlock Text="navBarGroup1" Grid.Row="1" Grid.Column="0"/>
</Grid>
</Window>