如何在WPF中使用WindowChrome而不带有Windows Aero玻璃效果,出现黑色边框

10
我正在尝试使用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>
1个回答

5

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

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

1
Microsoft.Windows.Shell.dll的最新版本(2010年5月7日),属性*"NonClientFrameEdges""UseAeroCaptionButtons"*都不存在。 - itsho
正如您在这里所看到的,这些属性是WindowChrome类的一部分。也许您使用了错误的命名空间。 - webber2k6
@itsho UseAeroCaptionButtons 可在 .NET 4.5 的 PresentationFramework.dll 程序集中使用,但在 .NET 4.0 中不可用。 - dss539
1
@dss539 是正确的,Microsoft将WindowChrome和所有其他外壳类从Microsoft.Windows.Shell命名空间中移动到了外部dll的PresantationFramework.dll和命名空间System.Windows.Shell中。但这仅适用于**.NET 4.5**!新链接 - webber2k6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接