【发布时间】:2018-07-04 19:07:05
【问题描述】:
我有以下窗口:
<Window x:Class="WpfApplication1.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"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen" ShowInTaskbar="True"
Style="{StaticResource BorderlessWindow}" SizeToContent="WidthAndHeight">
<Grid>
</Grid>
</Window>
在我的 App.xaml 中,我有以下无边框窗口样式:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="BorderlessWindow" TargetType="{x:Type Window}">
<Setter Property="MinWidth" Value="325" />
<Setter Property="MinHeight" Value="240" />
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome CaptionHeight="32"
GlassFrameThickness="0"
ResizeBorderThickness="12" />
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>
要让应用程序运行,您需要对 Microsoft.Windows.Shell 的引用。完整地说:我们使用的是 .NET Framework 4.0 和 VS 2015。
我已将SizeToContent="WidthAndHeight" 设置为获得更小的窗口,但是当我这样做时,我会在右侧和底部看到黑色“阴影”。通过 snoop 我看到 MainWindow 设置为 MinHeight 和 MinWidth,但里面的 Border 没有。
为什么内容没有调整大小?当通过鼠标调整窗口大小来更新窗口时,窗口看起来像预期的那样。
【问题讨论】: