WindowChrome Class

WindowChrome Class

.NET Framework (current version)
 

Represents an object that describes the customizations to the non-client area of a window.

Namespace:   System.Windows.Shell
Assembly:  PresentationFramework (in PresentationFramework.dll)

System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Freezable
        System.Windows.Shell.WindowChrome

public class WindowChrome : Freezable

NameDescription
System_CAPS_pubmethodWindowChrome()

Initializes a new instance of the WindowChrome class.

NameDescription
System_CAPS_pubpropertyCanFreeze

Gets a value that indicates whether the object can be made unmodifiable. (Inherited from Freezable.)

System_CAPS_pubpropertyCaptionHeight

Gets or sets the height of the caption area at the top of a window.

System_CAPS_pubpropertyCornerRadius

Gets or sets a value that indicates the amount that the corners of a window are rounded.

System_CAPS_pubpropertyDependencyObjectType

Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject.)

System_CAPS_pubpropertyDispatcher

Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)

System_CAPS_pubpropertySystem_CAPS_staticGlassFrameCompleteThickness

Gets a uniform thickness of -1.

System_CAPS_pubpropertyGlassFrameThickness

Gets or sets a value that indicates the width of the glass border around a window.

System_CAPS_pubpropertyIsFrozen

Gets a value that indicates whether the object is currently modifiable. (Inherited from Freezable.)

System_CAPS_pubpropertyIsSealed

Gets a value that indicates whether this instance is currently sealed (read-only).(Inherited from DependencyObject.)

System_CAPS_pubpropertyNonClientFrameEdges

Gets or sets a value that indicates which edges of the window frame are not owned by the client.

System_CAPS_pubpropertyResizeBorderThickness

Gets or sets a value that indicates the width of the border that is used to resize a window.

System_CAPS_pubpropertyUseAeroCaptionButtons

Gets or sets a value that indicates whether hit-testing is enabled on the Windows Aero caption buttons.

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticIsHitTestVisibleInChrome

Gets or sets a value that indicates whether WPF hit-testing is enabled on the part of an element that is in the non-client area of a window.

System_CAPS_pubpropertySystem_CAPS_staticResizeGripDirection

Gets or sets a value that indicates the direction of the resize grip behavior on an input element.

System_CAPS_pubpropertySystem_CAPS_staticWindowChrome

Gets or sets the instance of WindowChrome that is attached to a window.

NameDescription
System_CAPS_pubmethodCheckAccess()

Determines whether the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

System_CAPS_pubmethodClearValue(DependencyProperty)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.)

System_CAPS_pubmethodClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.)

System_CAPS_pubmethodClone()

Creates a modifiable clone of the Freezable, making deep copies of the object's values. When copying the object's dependency properties, this method copies expressions (which might no longer resolve) but not animations or their current values. (Inherited from Freezable.)

System_CAPS_protmethodCloneCore(Freezable)

Makes the instance a clone (deep copy) of the specified Freezable using base (non-animated) property values. (Inherited from Freezable.)

System_CAPS_pubmethodCloneCurrentValue()

Creates a modifiable clone (deep copy) of the Freezable using its current values.(Inherited from Freezable.)

System_CAPS_protmethodCloneCurrentValueCore(Freezable)

Makes the instance a modifiable clone (deep copy) of the specified Freezable using current property values.(Inherited from Freezable.)

System_CAPS_pubmethodCoerceValue(DependencyProperty)

Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.(Inherited from DependencyObject.)

System_CAPS_protmethodCreateInstance()

Initializes a new instance of the Freezable class. (Inherited from Freezable.)

System_CAPS_protmethodCreateInstanceCore()

Creates a new instance of the WindowChrome class.(Overrides Freezable.CreateInstanceCore().)

System_CAPS_pubmethodEquals(Object)

Determines whether a provided DependencyObject is equivalent to the current DependencyObject.(Inherited from DependencyObject.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodFreeze()

Makes the current object unmodifiable and sets its IsFrozen property to true. (Inherited from Freezable.)

System_CAPS_protmethodFreezeCore(Boolean)

Makes the Freezable object unmodifiable or tests whether it can be made unmodifiable.(Inherited from Freezable.)

System_CAPS_pubmethodGetAsFrozen()

Creates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.)

System_CAPS_protmethodGetAsFrozenCore(Freezable)

Makes the instance a frozen clone of the specified Freezable using base (non-animated) property values.(Inherited from Freezable.)

System_CAPS_pubmethodGetCurrentValueAsFrozen()

Creates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference.(Inherited from Freezable.)

System_CAPS_protmethodGetCurrentValueAsFrozenCore(Freezable)

Makes the current instance a frozen clone of the specified Freezable. If the object has animated dependency properties, their current animated values are copied.(Inherited from Freezable.)

System_CAPS_pubmethodGetHashCode()

Gets a hash code for this DependencyObject.(Inherited from DependencyObject.)

System_CAPS_pubmethodSystem_CAPS_staticGetIsHitTestVisibleInChrome(IInputElement)

Gets the value of the IsHitTestVisibleInChrome attached property from the specified input element.

System_CAPS_pubmethodGetLocalValueEnumerator()

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.)

System_CAPS_pubmethodSystem_CAPS_staticGetResizeGripDirection(IInputElement)

Gets the value of the ResizeGripDirection attached property from the specified input element.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetValue(DependencyProperty)

Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.)

System_CAPS_pubmethodSystem_CAPS_staticGetWindowChrome(Window)

Gets the value of the WindowChrome attached property from the specified Window.

System_CAPS_pubmethodInvalidateProperty(DependencyProperty)

Re-evaluates the effective value for the specified dependency property(Inherited from DependencyObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnChanged()

Called when the current Freezable object is modified. (Inherited from Freezable.)

System_CAPS_protmethodOnFreezablePropertyChanged(DependencyObject, DependencyObject)

Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set.(Inherited from Freezable.)

System_CAPS_protmethodOnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.(Inherited from Freezable.)

System_CAPS_protmethodOnPropertyChanged(DependencyPropertyChangedEventArgs)

Overrides the DependencyObject implementation of OnPropertyChanged to also invoke any Changed handlers in response to a changing dependency property of type Freezable.(Inherited from Freezable.)

System_CAPS_pubmethodReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject.)

System_CAPS_protmethodReadPreamble()

Ensures that the Freezable is being accessed from a valid thread. Inheritors of Freezable must call this method at the beginning of any API that reads data members that are not dependency properties.(Inherited from Freezable.)

System_CAPS_pubmethodSetCurrentValue(DependencyProperty, Object)

Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject.)

System_CAPS_pubmethodSystem_CAPS_staticSetIsHitTestVisibleInChrome(IInputElement, Boolean)

Sets the value of the IsHitTestVisibleInChrome attached property on the specified input element.

System_CAPS_pubmethodSystem_CAPS_staticSetResizeGripDirection(IInputElement, ResizeGripDirection)

Sets the value of the ResizeGripDirection attached property on the specified input element.

System_CAPS_pubmethodSetValue(DependencyProperty, Object)

Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.)

System_CAPS_pubmethodSetValue(DependencyPropertyKey, Object)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.)

System_CAPS_pubmethodSystem_CAPS_staticSetWindowChrome(Window, WindowChrome)

Sets the value of the WindowChrome attached property on the specified Window.

System_CAPS_protmethodShouldSerializeProperty(DependencyProperty)

Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.(Inherited from DependencyObject.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodVerifyAccess()

Enforces that the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

System_CAPS_protmethodWritePostscript()

Raises the Changed event for the Freezable and invokes its OnChanged method. Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties.(Inherited from Freezable.)

System_CAPS_protmethodWritePreamble()

Verifies that the Freezable is not frozen and that it is being accessed from a valid threading context. Freezable inheritors should call this method at the beginning of any API that writes to data members that are not dependency properties. (Inherited from Freezable.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticCaptionHeightProperty

Identifies the CaptionHeight dependency property.

System_CAPS_pubfieldSystem_CAPS_staticCornerRadiusProperty

Identifies the CornerRadius dependency property.

System_CAPS_pubfieldSystem_CAPS_staticGlassFrameThicknessProperty

Identifies the GlassFrameThickness dependency property.

System_CAPS_pubfieldSystem_CAPS_staticIsHitTestVisibleInChromeProperty

Identifies the IsHitTestVisibleInChrome dependency property.

System_CAPS_pubfieldSystem_CAPS_staticNonClientFrameEdgesProperty

Identifies the NonClientFrameEdges dependency property.

System_CAPS_pubfieldSystem_CAPS_staticResizeBorderThicknessProperty

Identifies the ResizeBorderThickness dependency property.

System_CAPS_pubfieldSystem_CAPS_staticResizeGripDirectionProperty

Identifies the ResizeGripDirection dependency property.

System_CAPS_pubfieldSystem_CAPS_staticUseAeroCaptionButtonsProperty

Identifies the UseAeroCaptionButtons dependency property.

System_CAPS_pubfieldSystem_CAPS_staticWindowChromeProperty

Identifies the WindowChrome dependency property.

NameDescription
System_CAPS_pubeventChanged

Occurs when the Freezable or an object it contains is modified. (Inherited from Freezable.)

The WindowChrome class enables you to extend Windows Presentation Foundation (WPF) content into the non-client area of a window that is typically reserved for the operating system’s window manager.

Standard windows are composed of two overlapping rectangles. The outer rectangle is the non-client area, which is often referred to as chrome. It is drawn and managed by the operating system’s window manager. Its dimensions are determined by standard operating system settings. The non-client frame provides standard window features and behaviors. These include caption buttons (Minimize, Maximize, and Close), the window border, resize and move behaviors, the application icon and title, and the system menu. The inner rectangle is the client area. It contains the contents of your application, and it is drawn and managed by the application. For more information about windows in WPF applications, see WPF Windows Overview.

The following illustration shows the parts of a standard window.

Window elements

You can customize a window border by setting the Window.WindowStyle property to None or by using the WindowChrome class.

One way to customize the appearance of a WPF application window is to set the Window.WindowStyle property to None. This removes the non-client frame from the window and leaves only the client area, to which you can apply a custom style. However, when the non-client frame is removed, you also lose the system features and behaviors that it provides, such as caption buttons and window resizing. Another side effect is that the window will cover the Windows taskbar when it is maximized. Setting WindowStyle.None enables you to create a completely custom application, but also requires that you implement custom logic in your application to emulate standard window behavior.

To customize a window while retaining its standard functionality, you can use the WindowChrome class. The WindowChrome class separates the functionality of the window frame from the visuals, and lets you control the boundary between the client and non-client areas of your application window. The WindowChrome class lets you put WPF content in the window frame by extending the client area to cover the non-client area. At the same time, it retains system behaviors through two invisible areas; the resize border and captionareas.

There are two main parts to creating a custom window using the WindowChrome class. First, you customize the non-client part of the window by setting properties exposed on the WindowChrome object. Then you provide a template for the window that defines the part of your application that is extended into the non-client area.The properties exposed on the WindowChrome object are ResizeBorderThickness, CaptionHeight, CornerRadius, and GlassFrameThickness.

The ResizeBorderThickness property specifies an invisible border around the outside of the application window that the user can click-and-drag to resize the window.

The CaptionHeight property specifies an invisible area at the top of the window that enables system behaviors typically associated with the title bar. These behaviors include: click and drag to move the window, double-click to maximize the window, and right-click to show the system menu.

The resize border and caption area do not have any visual elements; they only define areas that respond to input and enable standard system-provided window behaviors.

The CornerRadius property specifies the amount that the corners of the window are rounded. This property does not have any effect if the glass frame is enabled for a window.

The GlassFrameThickness property specifies the width of the glass frame around the window. By default, it uses the system value specified by the P:System.Windows.Shell.SystemParameters2.WindowNonClientFrameThickness property to emulate the appearance of a standard window. When the glass frame is used, the caption buttons for Minimize, Maximize, and Close are visible and interactive. The application is responsible for displaying the application icon and caption text. You can set the GlassFrameThickness property to make the glass frame wider or narrower than the default.

System_CAPS_cautionCaution

The size of the caption buttons does not change when the GlassFrameThickness property is changed. If the height of the top of the glass frame is less than the height of the caption buttons, the caption buttons will not be completely visible.

To make a custom window that does not have a glass frame, set the GlassFrameThickness property to a uniform value of 0. This will disable and hide the standard caption buttons.

To extend the glass frame to cover the entire window, set the GlassFrameThickness property to a negative value on any side. When the GlassFrameThickness property is set to a negative value for any side, its coerced value will be equal to GlassFrameCompleteThickness.

System_CAPS_noteNote

Aero is a set of visual enhancements to the look and functionality of the Windows desktop that was introduced in Windows Vista. One of the more visually obvious features of Aero is translucent glass window borders. Windows Aero is enabled by the desktop composition feature of the Desktop Window Manager (DWM).

Windows Aero glass effects are not supported on all operating systems, and can be disabled on supported operating systems. If Windows Aero is not available, the glass frame will not be displayed regardless of the GlassFrameThickness property value. The border area specified by this property will appear black instead.Check the P:System.Windows.Shell.SystemParameters2.IsGlassEnabled property to verify that Windows Aero glass effects are available. If glass effects are not available, you should provide an alternate window style that does not use the glass frame or use the standard window by setting the window style to null.

You extend your WPF content into the window frame by specifying a ControlTemplate that defines the appearance and behavior of the frame content. You set the TargetType of the ControlTemplate to the type of the window that you are customizing.

<ControlTemplate TargetType="{x:Type local:MainWindow}">

By default, the parts of any visual elements that are within the non-client area of the window are not interactive. To enable interactive elements in the non-client area, attach the WindowsChrome.IsHitTestVisibleInChrome attached property to the element and set it to true.

The following XAML markup shows the main elements needed to customize a window using the WindowChrome class.

<Style x:Key="StandardStyle" TargetType="{x:Type local:MainWindow}">
    <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
            <shell:WindowChrome />
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:MainWindow}">
                <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>

The first setter attaches the WindowChrome to the window. It uses all default values for the WindowChrome properties, which makes the window look like a standard window.

<Setter Property="shell:WindowChrome.WindowChrome">
    <Setter.Value>
        <shell:WindowChrome />
    </Setter.Value>
</Setter>

The window template must specify a content presenter to display the contents of the window specified in your application. By default the WindowChrome class extends the client area to cover the non-client border. In order to uncover the glass frame, you need to specify a margin around the ContentPresenter. This markup specifies a border with a white background around the content presenter to emulate the appearance of a standard window. It also specifies a margin that is bound to the WindowNonClientFrameThickness property, which gets the default system width for the frame.

<Border Background="White"
    Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
    <ContentPresenter Content="{TemplateBinding Content}" />
</Border>

The application icon and title are not displayed by the WindowChrome class; they have to be added to the border as custom content. The following XAML adds an image and a textblock to display the icon and title. Both elements are bound to the corresponding properties on the window. The image width is bound to the SmallIconSize width, which gets the default system size for the icon. The IsHitTestVisibleInChrome attached property is set on the image so that it can receive mouse events.

<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"/>


<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" 
           VerticalAlignment="Top" HorizontalAlignment="Left" 
           Margin="36,8,0,0"/>

.NET Framework
Available since 4.5

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft