【发布时间】:2017-02-01 01:21:49
【问题描述】:
问题是 Windows 10 的边框太厚了。
如果你没有看到下面的截图,那么这里是文字:
- 此边框在左、右和底部太粗
- 这些边缘的边框也更亮
如何制作像 Google Chrome(或 Windows 10 的资源管理器)一样的 1px 边框?负 1px 效果不好,它使边框变白而且仍然很厚。
框架是 .NET Framework 4.6.2。
代码:
<Window
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:AnotherOffice"
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Name="window" x:Class="AnotherOffice.MainWindow"
mc:Ignorable="d"
Title="AnotherOffice Text v0.0.1 - New document" Height="720" Width="1280" Background="{x:Null}" WindowState="Maximized" Margin="0" BorderThickness="8">
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome
GlassFrameThickness="8,40,8,8"
ResizeBorderThickness="2"
CornerRadius="0"
CaptionHeight="32"
UseAeroCaptionButtons="True"
/>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
<local:AnotherOfficeTextBase Margin="0,32,0,0"/>
</Window>
UPD:尝试使用此代码:
if (SystemParameters.IsGlassEnabled)
{
WindowChrome winChrome = new WindowChrome();
winChrome.CaptionHeight = 32;
winChrome.CornerRadius = new CornerRadius(0);
winChrome.GlassFrameThickness = new Thickness(8, 32, 8, 8);
winChrome.ResizeBorderThickness = new Thickness(1);
winChrome.UseAeroCaptionButtons = true;
WindowChrome.SetWindowChrome(this, winChrome);
InitializeComponent();
} else
{
MainWindowNoGlass fallback = new MainWindowNoGlass();
fallback.Show();
Close();
}
而且...没有效果。
【问题讨论】:
-
我只使用 Mah.Apps 窗口样式(尽管我不再使用他们的 Metro Interface 样式)。然后我知道它将在整个操作系统中保持一致,并且可以更好地控制所有元素。
-
@Joe 我想使用我自己的解决方案,因为我想在我的窗口镶边中有一个 TabControl。有什么想法吗?
-
啊,当然。我会看看他们的 BorderlessWindowBehavior 代码然后github.com/MahApps/MahApps.Metro/blob/…。
-
@Joe 我猜他们使用的是较旧的 .NET Framework 版本,因为他们使用的是
Microsoft.Windows.Shell而不是System.Windows.Shell这就是为什么我不确定它是否会起作用。还是我有什么不明白?
标签: c# wpf xaml .net-4.6 window-chrome