【问题标题】:WindowChrome - too thick border for Windows 10WindowChrome - Windows 10 的边框太厚
【发布时间】:2017-02-01 01:21:49
【问题描述】:

问题是 Windows 10 的边框太厚了。

如果你没有看到下面的截图,那么这里是文字:

  1. 此边框在左、右和底部太粗
  2. 这些边缘的边框也更亮

如何制作像 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


【解决方案1】:

这是我想出的最简单的解决方案:

去掉所有与边框粗细、窗口镶边等相关的代码。 在主窗口的 xaml 内容区域的顶部,粘贴以下内容:

<WindowChrome.WindowChrome>
    <WindowChrome GlassFrameThickness="0.5,28,0,0.5" NonClientFrameEdges="Right"/>
</WindowChrome.WindowChrome>
<Window.Template>
    <ControlTemplate>
        <ContentPresenter Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Content}"/>
    </ControlTemplate>
</Window.Template>

这将处理一切。您可以在非客户端区域轻松绘制内容,并且窗口看起来会正常(足够)。如果你真的需要背景也是白色的,你可以将GlassFrameThickness设置为-1,并在底部和左侧画一个0.5单位的边框。否则,你可以只画一个大的白色矩形。

【讨论】:

    猜你喜欢
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 2015-11-13
    • 1970-01-01
    相关资源
    最近更新 更多