如何在 wpf 中使用 WindowChrome 而不使用 Windows Aero 玻璃效果,黑色边框

发布于 2024-10-26 02:19:45 字数 2656 浏览 0 评论 0原文

我正在尝试使用 WindowChrome 类自定义窗口边框。没有 Windows Aero 玻璃效果。正如预期的那样,我最终得到了一个黑人寄宿生。 但我最终也没有标题按钮

从微软我了解到我可以通过将窗口样式设置为 null 来使用标准窗口来克服这些问题 http://msdn.microsoft.com/en- us/library/microsoft.windows.shell.windowchrome.aspx

但我没有成功。

有人有这方面的工作示例吗?或者某种可以解释如何解决我的问题的链接?

我尝试编写一个简单的示例代码,并将 WindowStyle 更改为 none,但它不起作用。这是我的示例代码:

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell" Title="Window" Height="400" Width="500">
    <Window.Style>
        <Style TargetType="{x:Type Window}">
            <Setter Property="shell:WindowChrome.WindowChrome">
                <Setter.Value>
                    <shell:WindowChrome />
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <Grid>
                            <Border Background="White" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
                                <ContentPresenter Content="{TemplateBinding Content}" />
                            </Border>
                            <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" 
                               VerticalAlignment="Top" HorizontalAlignment="Left" 
                               Margin="36,8,0,0"/>
                            <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}"
                           VerticalAlignment="Top" HorizontalAlignment="Left"
                           Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}" 
                           Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=SmallIconSize.Width}"
                           shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Style>
    <Grid/>
</Window>

I'm trying to customize a window border by using the WindowChrome class. Without Windows Aero glass effects. As expected I end up with a black boarder.
But i also end up without caption buttons

From Microsoft i learn that i can use the standard window by setting the window style to null to overcome these problem
http://msdn.microsoft.com/en-us/library/microsoft.windows.shell.windowchrome.aspx

But i do not succeed with that.

Do anyone have a working example of this? Or a link of some sort that can explain how to solve my problem?

I have tried to do a simple example code, and change the WindowStyle to none but it wont work. This is my example code:

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell" Title="Window" Height="400" Width="500">
    <Window.Style>
        <Style TargetType="{x:Type Window}">
            <Setter Property="shell:WindowChrome.WindowChrome">
                <Setter.Value>
                    <shell:WindowChrome />
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <Grid>
                            <Border Background="White" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
                                <ContentPresenter Content="{TemplateBinding Content}" />
                            </Border>
                            <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" 
                               VerticalAlignment="Top" HorizontalAlignment="Left" 
                               Margin="36,8,0,0"/>
                            <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}"
                           VerticalAlignment="Top" HorizontalAlignment="Left"
                           Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}" 
                           Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=SmallIconSize.Width}"
                           shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Style>
    <Grid/>
</Window>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚人国度 2024-11-02 02:19:46

我也在尝试 WindowChrome,到目前为止,我的应用程序工作正常:

<Window ...>
    <Window.Style>
        <Style TargetType="{x:Type Window}">
            <Setter Property="shell:WindowChrome.WindowChrome">
                <Setter.Value>
                    <shell:WindowChrome CaptionHeight="15"
                                        CornerRadius="0"
                                        GlassFrameThickness="0,0,0,-1"
                                        NonClientFrameEdges="None"
                                        ResizeBorderThickness="5"
                                        UseAeroCaptionButtons="true"/>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Style>
    <!-- Add content to normal window content (not with template, at first) -->
    <Grid>

    </Grid>
</Window>

如果您使用上面的代码,您应该有一个空窗口,只有标题按钮和一个玻璃窗口。

I'm experimenting with WindowChrome too and my application works so far:

<Window ...>
    <Window.Style>
        <Style TargetType="{x:Type Window}">
            <Setter Property="shell:WindowChrome.WindowChrome">
                <Setter.Value>
                    <shell:WindowChrome CaptionHeight="15"
                                        CornerRadius="0"
                                        GlassFrameThickness="0,0,0,-1"
                                        NonClientFrameEdges="None"
                                        ResizeBorderThickness="5"
                                        UseAeroCaptionButtons="true"/>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Style>
    <!-- Add content to normal window content (not with template, at first) -->
    <Grid>

    </Grid>
</Window>

You should have an empty window with nothing more than the caption buttons and a glass window if you use my code above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文