Поделиться через


ChildWindow.HasCloseButton Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates whether the ChildWindow has a close button.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)

Syntax

'Declaration
Public Property HasCloseButton As Boolean
public bool HasCloseButton { get; set; }
<sdk:ChildWindow HasCloseButton="bool"/>

Property Value

Type: System.Boolean
true if the child window has a close button; otherwise, false. The default is true.

Remarks

Dependency property identifier field: HasCloseButtonProperty

By default, a child window displays a close button in the title bar. You can hide the default close button by setting the HasCloseButton property to false. This can be useful if you want to prevent a user from dismissing the information displayed in the child window. For example, you might display a video message and then close the child window automatically when the video is finished, or you might display a message for a set period of time before letting the user close the window.

If the default close button is hidden, you should call the Close method in your code to close the child window or provide an alternative way for the user to close the child window.

Examples

The following example demonstrates a child window that does not have a close button. This example is part of a larger example available in the ChildWindow class overview.

Run this sample

The following shows how to set the HasCloseButton property in XAML:

<!-- NOTE: 
  By convention, the sdk prefix indicates a URI-based XAML namespace declaration 
  for Silverlight SDK client libraries. This namespace declaration is valid for 
  Silverlight 4 only. In Silverlight 3, you must use individual XAML namespace 
  declarations for each CLR assembly and namespace combination outside the scope 
  of the default Silverlight XAML namespace. For more information, see the help 
  topic "Prefixes and Mappings for Silverlight Libraries". 
-->
<sdk:ChildWindow x:Class="ChildWindowSplash.SplashWindow"
           xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:sdk="https://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           Width="200" Height="150"
           HasCloseButton="False"
           OverlayBrush="{StaticResource overlayGradient}"
           OverlayOpacity="0.85">

The following shows how to set the HasCloseButton property in code:

Me.HasCloseButton = False
this.HasCloseButton = false;

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.