右侧和左侧的粗边框

时间:2022-06-25 09:25:39

My RibbonWindow Desktop Application shows a thick black border on both sides in Windows 10. You can reproduce this by a simple WPF Application showing a RibbonWindow. The border is not showing on Windows 8.x.

我的RibbonWindow桌面应用程序在Windows 10的两侧都显示一个粗黑边框。您可以通过显示RibbonWindow的简单WPF应用程序重现这一点。 Windows 8.x上未显示边框。

Does anybody know, how to remove the border?

有人知道,如何删除边界?

右侧和左侧的粗边框

Some guy asked a similar question on msdn, and the answer 'it's a known issue'. But following the provided link I can't find any specific.

有人在msdn上问了一个类似的问题,答案是'这是一个已知的问题'。但是根据提供的链接我找不到任何具体的。

So can anybody help me out of this?

所以有人可以帮我解决这个问题吗?

Edit: the color of the borders is black, if the window is not active. If the window is active, the border get the color from the customized windows accent color.

编辑:如果窗口未激活,则边框的颜色为黑色。如果窗口处于活动状态,则边框将从自定义窗口强调颜色中获取颜色。

1 个解决方案

#1


2  

Consider using WindowChrome with GlassFrameThickness = GlassFrameCompleteThickness.

考虑使用WindowChrome和GlassFrameThickness = GlassFrameCompleteThickness。

This is not an ideal solution - you'd have to carefully make room for the window title as well as the maximize, minimize and close buttons. That said, it does get rid of the border problem you are dealing with.

这不是一个理想的解决方案 - 你必须小心地为窗口标题腾出空间,以及最大化,最小化和关闭按钮。也就是说,它确实摆脱了你正在处理的边界问题。

For an example of how to manage the layout of content when WindowChrome is in use, see this SO answer.

有关如何在使用WindowChrome时管理内容布局的示例,请参阅此SO答案。

Here is a complete XAML that should also help:

这是一个完整的XAML,也应该有所帮助:

<RibbonWindow x:Class="RibbonTest.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:RibbonTest"
              xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
        mc:Ignorable="d"
        Title="RibbonWindow" Height="350" Width="525">
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="{x:Static shell:WindowChrome.GlassFrameCompleteThickness}"/>
    </WindowChrome.WindowChrome>
    <Window.Template>
        <ControlTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>

                <!-- Opacity of < 1.0 helps show the minimize, maximize and close buttons -->
                <Border Grid.Row="0" Background="Wheat" Opacity="0.8">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30" />
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>


                        <!-- Window Title - Center Aligned -->
                        <TextBlock 
                            Grid.Column="1"
                            TextAlignment="Center" 
                            VerticalAlignment="Center"
                            Text="{Binding Title, RelativeSource={RelativeSource TemplatedParent}}" />

                    </Grid>
                </Border>

                <!-- This is the Window's main content area -->
                <!-- Top margin 44 = WindowChrome ResizeBorderThickness (4) + CaptionHeight(40) -->
                <!-- Bottom margin 1 is somewhat arbitrary -->
                <Border Grid.Row="1" Background="White" Opacity="0.5">
                    <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/>
                </Border>
            </Grid>
        </ControlTemplate>
    </Window.Template>
    <Grid>
        <Border Background="Cyan" BorderBrush="BlanchedAlmond" BorderThickness="5">
            <Label FontSize="80" HorizontalAlignment="Center" VerticalAlignment="Center">Hello World</Label>
        </Border>
    </Grid>
</RibbonWindow>

The resulting RibbonWindow would look something like this:

生成的RibbonWindow看起来像这样:

右侧和左侧的粗边框

#1


2  

Consider using WindowChrome with GlassFrameThickness = GlassFrameCompleteThickness.

考虑使用WindowChrome和GlassFrameThickness = GlassFrameCompleteThickness。

This is not an ideal solution - you'd have to carefully make room for the window title as well as the maximize, minimize and close buttons. That said, it does get rid of the border problem you are dealing with.

这不是一个理想的解决方案 - 你必须小心地为窗口标题腾出空间,以及最大化,最小化和关闭按钮。也就是说,它确实摆脱了你正在处理的边界问题。

For an example of how to manage the layout of content when WindowChrome is in use, see this SO answer.

有关如何在使用WindowChrome时管理内容布局的示例,请参阅此SO答案。

Here is a complete XAML that should also help:

这是一个完整的XAML,也应该有所帮助:

<RibbonWindow x:Class="RibbonTest.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:RibbonTest"
              xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
        mc:Ignorable="d"
        Title="RibbonWindow" Height="350" Width="525">
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="{x:Static shell:WindowChrome.GlassFrameCompleteThickness}"/>
    </WindowChrome.WindowChrome>
    <Window.Template>
        <ControlTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>

                <!-- Opacity of < 1.0 helps show the minimize, maximize and close buttons -->
                <Border Grid.Row="0" Background="Wheat" Opacity="0.8">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30" />
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>


                        <!-- Window Title - Center Aligned -->
                        <TextBlock 
                            Grid.Column="1"
                            TextAlignment="Center" 
                            VerticalAlignment="Center"
                            Text="{Binding Title, RelativeSource={RelativeSource TemplatedParent}}" />

                    </Grid>
                </Border>

                <!-- This is the Window's main content area -->
                <!-- Top margin 44 = WindowChrome ResizeBorderThickness (4) + CaptionHeight(40) -->
                <!-- Bottom margin 1 is somewhat arbitrary -->
                <Border Grid.Row="1" Background="White" Opacity="0.5">
                    <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/>
                </Border>
            </Grid>
        </ControlTemplate>
    </Window.Template>
    <Grid>
        <Border Background="Cyan" BorderBrush="BlanchedAlmond" BorderThickness="5">
            <Label FontSize="80" HorizontalAlignment="Center" VerticalAlignment="Center">Hello World</Label>
        </Border>
    </Grid>
</RibbonWindow>

The resulting RibbonWindow would look something like this:

生成的RibbonWindow看起来像这样:

右侧和左侧的粗边框