【问题标题】:How to use WindowChrome without Windows Aero glass effects in wpf, black border如何在wpf中使用没有Windows Aero玻璃效果的WindowChrome,黑色边框
【发布时间】:2011-07-22 18:00:32
【问题描述】:

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

从 Microsoft 我了解到我可以通过将窗口样式设置为 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>

【问题讨论】:

    标签: c# wpf .net-4.0 aero-glass window-chrome


    【解决方案1】:

    我也在尝试使用 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>
    

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

    【讨论】:

    • Microsoft.Windows.Shell.dll 最新版本(2010 年 5 月 7 日)上,两个属性 "NonClientFrameEdges""UseAeroCaptionButtons" 不存在
    • 如您所见here,这些属性是WindowChrome 类的一部分。也许你使用了错误的命名空间。
    • @itsho UseAeroCaptionButtons 在 .NET 4.5 程序集 PresentationFramework.dll 中可用。它在 .NET 4.0 中不可用
    • @dss539 是对的,微软将WindowChrome 和所有其他shell 类从外部dll 中的Microsoft.Windows.Shell 命名空间移至PresantationFramework.dll 和命名空间System.Windows.Shell。但这仅适用于 .NET 4.5new link
    猜你喜欢
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 2013-08-22
    • 2010-12-24
    • 2011-05-05
    • 2010-11-28
    • 1970-01-01
    相关资源
    最近更新 更多