How to use WindowChrome without Windows Aero glass effects in wpf, black border
Asked Answered
W

1

10

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>
Wasp answered 25/3, 2011 at 8:21 Comment(0)
Z
5

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.

Zoarah answered 26/6, 2012 at 10:43 Comment(4)
On Microsoft.Windows.Shell.dll latest version (May 7 2010), both properties "NonClientFrameEdges" and "UseAeroCaptionButtons" does not existOrose
As you can see here, these properties are part of the WindowChrome class. Maybe you use a wrong namespace.Zoarah
@Orose UseAeroCaptionButtons is available in the .NET 4.5 assembly PresentationFramework.dll. It is not available in .NET 4.0Contrabass
@Contrabass is right, Microsoft moved the WindowChrome and all other shell class from Microsoft.Windows.Shell namespace in the external dll to the PresantationFramework.dll and the namespace System.Windows.Shell. But this is only available with .NET 4.5! new linkZoarah

© 2022 - 2024 — McMap. All rights reserved.