WindowControl Class
Represents a ContentControl that renders like a normal native Window
but can be used in other non-top-level contexts.
[TemplateVisualState(Name = "Active", GroupName = "ActiveStates")]
[TemplateVisualState(Name = "Inactive", GroupName = "ActiveStates")]
[TemplateVisualState(Name = "FrameHidden", GroupName = "FrameStates")]
[TemplateVisualState(Name = "FrameVisible", GroupName = "FrameStates")]
[TemplateVisualState(Name = "Editable", GroupName = "ReadOnlyStates")]
[TemplateVisualState(Name = "ReadOnly", GroupName = "ReadOnlyStates")]
[TemplateVisualState(Name = "Maximized", GroupName = "WindowStates")]
[TemplateVisualState(Name = "Minimized", GroupName = "WindowStates")]
[TemplateVisualState(Name = "Restored", GroupName = "WindowStates")]
[TemplatePart(Name = "PART_Icon", Type = typeof(FrameworkElement))]
[TemplatePart(Name = "PART_TitleBar", Type = typeof(FrameworkElement))]
public class WindowControl : ContentControl, DUCE.IResource, IAnimatable, IFrameworkInputElement, IInputElement, ISupportInitialize, IHaveResources, IQueryAmbient, IAddChild, IBoundsProvider
- Inheritance:
- Object DispatcherObject DependencyObject Visual UIElement FrameworkElement Control ContentControl Object
Constructors
WindowControl()
Initializes an instance of the WindowControl
class.
public WindowControl()
Properties
CanClose
Gets or sets whether the window can close.
public bool CanClose { get; set; }
Property Value
- Boolean:
true
if the window can close; otherwise,false
. The default value istrue
.
CloseCommand
Gets the ICommand that can close the window.
public ICommand CloseCommand { get; }
Property Value
ContextContent
Gets or sets the context content that is displayed on the title bar next to the title.
public object ContextContent { get; set; }
Property Value
- Object:
The context content that is displayed on the title bar next to the title. The default value is null.
ContextContentTemplate
Gets or sets the DataTemplate to use for the ContextContent.
public DataTemplate ContextContentTemplate { get; set; }
Property Value
- DataTemplate:
The DataTemplate to use for the ContextContent. The default value is null.
ContextContentTemplateSelector
Gets or sets the DataTemplateSelector to use for the ContextContent.
public DataTemplateSelector ContextContentTemplateSelector { get; set; }
Property Value
- DataTemplateSelector:
The DataTemplateSelector to use for the ContextContent. The default value is null.
CornerRadius
Gets or sets the CornerRadius of the window.
public CornerRadius CornerRadius { get; set; }
Property Value
- CornerRadius:
The CornerRadius of the window. The default value is
0.0
.
HasCloseButton
Gets or sets whether the window is capable of displaying a close button.
public bool HasCloseButton { get; set; }
Property Value
- Boolean:
true
if the window is capable of displaying a close button; otherwise,false
. The default value istrue
.
HasDropShadow
Gets or sets whether the window has a drop shadow.
public bool HasDropShadow { get; set; }
Property Value
- Boolean:
true
if the window has a drop shadow; otherwise,false
. The default value isfalse
.
HasIcon
Gets or sets whether the window is capable of displaying an icon.
public bool HasIcon { get; set; }
Property Value
- Boolean:
true
if the window is capable of displaying an icon; otherwise,false
. The default value istrue
.
HasMaximizeButton
Gets or sets whether the window is capable of displaying a maximize button.
public bool HasMaximizeButton { get; set; }
Property Value
- Boolean:
true
if the window is capable of displaying a maximize button; otherwise,false
. The default value istrue
.
HasMinimizeButton
Gets or sets whether the window is capable of displaying a minimize button.
public bool HasMinimizeButton { get; set; }
Property Value
- Boolean:
true
if the window is capable of displaying a minimize button; otherwise,false
. The default value istrue
.
HasRestoreButton
Gets or sets whether the window is capable of displaying a restore button.
public bool HasRestoreButton { get; set; }
Property Value
- Boolean:
true
if the window is capable of displaying a restore button; otherwise,false
. The default value istrue
.
HasTitleBar
Gets or sets whether the window is capable of displaying a title bar.
public bool HasTitleBar { get; set; }
Property Value
- Boolean:
true
if the window is capable of displaying a title bar; otherwise,false
. The default value istrue
.
Icon
Gets or sets the ImageSource displayed as the window icon.
public ImageSource Icon { get; set; }
Property Value
- ImageSource:
The ImageSource displayed as the window icon. The default value is null.
IsActive
Gets whether the window is currently active.
public bool IsActive { get; protected set; }
Property Value
- Boolean:
true
if the window is currently active; otherwise,false
.
IsCloseButtonVisible
Gets whether the window's close button is visible.
public bool IsCloseButtonVisible { get; }
Property Value
- Boolean:
true
if the window's close button is visible; otherwise,false
. The default value istrue
.
IsMaximizeButtonVisible
Gets whether the window's maximize button is visible.
public bool IsMaximizeButtonVisible { get; }
Property Value
- Boolean:
true
if the window's maximize button is visible; otherwise,false
. The default value isfalse
.
IsMaximizedFrameVisible
Gets or sets whether the frame should be displayed when the window is maximized.
public bool IsMaximizedFrameVisible { get; set; }
Property Value
- Boolean:
true
if the frame should be displayed when the window is maximized; otherwise,false
. The default value istrue
.
IsMinimizeButtonVisible
Gets whether the window's minimize button is visible.
public bool IsMinimizeButtonVisible { get; }
Property Value
- Boolean:
true
if the window's minimize button is visible; otherwise,false
. The default value isfalse
.
IsMoving
Gets whether the window is currently being dragged to move its location.
public bool IsMoving { get; }
Property Value
- Boolean:
true
if the window is currently being dragged to move its location; otherwise,false
.
IsReadOnly
Gets or sets whether the windows's contents are read-only.
public bool IsReadOnly { get; set; }
Property Value
- Boolean:
true
if the windows's contents are read-only; otherwise,false
. The default value isfalse
.
IsResizing
Gets whether the window is currently being dragged to alter its size.
public bool IsResizing { get; }
Property Value
- Boolean:
true
if the window is currently being dragged to alter its size; otherwise,false
.
IsRestoreButtonVisible
Gets whether the window's restore button is visible.
public bool IsRestoreButtonVisible { get; }
Property Value
- Boolean:
true
if the window's restore button is visible; otherwise,false
. The default value isfalse
.
Left
Gets or sets the position of the window's left edge, in relation to its container.
public double Left { get; set; }
Property Value
- Double:
The position of the window's left edge, in relation to its container.
MaximizeCommand
Gets the ICommand that can maximize the window.
public ICommand MaximizeCommand { get; }
Property Value
MinimizeCommand
Gets the ICommand that can minimize the window.
public ICommand MinimizeCommand { get; }
Property Value
ReadOnlyContextContentTemplate
Gets or sets the DataTemplate to assign to ContextContentTemplate when the IsReadOnly property is true
.
public DataTemplate ReadOnlyContextContentTemplate { get; set; }
Property Value
- DataTemplate:
The DataTemplate to assign to ContextContentTemplate when the IsReadOnly property is
true
.
ResizeMode
Gets or sets a ResizeMode indicating how the window is able to resize.
public ResizeMode ResizeMode { get; set; }
Property Value
- ResizeMode:
A ResizeMode indicating how the window is able to resize. The default value is
CanResize
.
RestoreCommand
Gets the ICommand that can restore the window.
public ICommand RestoreCommand { get; }
Property Value
RestoredBounds
Gets or sets the bounds of this window when in a 'restored' state.
public Rect RestoredBounds { get; set; }
Property Value
- Rect:
The bounds of this window when in a 'restored' state.
ShadowElevation
Gets or sets the shadow elevation.
public int ShadowElevation { get; set; }
Property Value
- Int32:
The shadow elevation. The default value is
8
.
Remarks
Set this property to 0
to disable the shadow.
Title
Gets or sets the title of the window.
[Localizability(LocalizationCategory.Title)]
public string Title { get; set; }
Property Value
- String:
The title of the window.
TitleBarFontWeight
Gets or sets the FontWeight of the title.
public FontWeight TitleBarFontWeight { get; set; }
Property Value
- FontWeight:
The FontWeight of the title. The default value is
Normal
.
Top
Gets or sets the position of the window's top edge, in relation to its container.
public double Top { get; set; }
Property Value
- Double:
The position of the window's top edge, in relation to its container.
WindowState
Gets or sets a WindowState indicating the current state of the window.
public WindowState WindowState { get; set; }
Property Value
- WindowState:
A WindowState indicating the current state of the window. The default value is
Normal
.
Methods
Activate()
Attempts to bring the window to the foreground and activates it.
public virtual bool Activate()
Returns
- Boolean:
true
if the window was successfully activated; otherwise,false
.
Close()
Closes the window.
public void Close()
DragMove(InputPointerButtonEventArgs)
Allows a window to be dragged by a pointer with its primary button down over an exposed area of the window's client rectangle.
public void DragMove(InputPointerButtonEventArgs e)
Parameter | Type | Description |
---|---|---|
e | InputPointerButtonEventArgs | The InputPointerButtonEventArgs that can wrap a platform-specific input event args instance. |
Remarks
The primary button of the pointer in the event arguments must be pressed down when calling this method. The pointer will be captured.
GetAdjustedBounds(Rect, ResizeOperation)
Returns an adjusted version of the specified bounds, which can provide support for features such as magnetism.
public virtual Rect GetAdjustedBounds(Rect bounds, ResizeOperation resizeOperation)
Parameter | Type | Description |
---|---|---|
bounds | Rect | The bounds to examine. |
resizeOperation | ResizeOperation | The active resize operation. |
Returns
- Rect:
The adjusted bounds.
HitTestResizeOperation(Point)
Hit tests the specified Point to see if it might cause a resize operation.
public ResizeOperation HitTestResizeOperation(Point point)
Parameter | Type | Description |
---|---|---|
point | Point | The Point, in control coordinates, to hit test. |
Returns
- ResizeOperation:
The resize operation that can be caused by dragging at the Point.
OnActivated(RoutedEventArgs)
Called when the window gains focus within.
protected virtual void OnActivated(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnApplyTemplate()
Invoked whenever application code or internal processes call ApplyTemplate
.
public override void OnApplyTemplate()
OnClosed(RoutedEventArgs)
Called when the window is about to close.
protected virtual void OnClosed(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnClosing(CancelRoutedEventArgs)
Called directly after Close() is called, and can be handled to cancel window closure.
protected virtual void OnClosing(CancelRoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | CancelRoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnCreateAutomationPeer()
Returns an AutomationPeer object for this control instance.
protected override AutomationPeer OnCreateAutomationPeer()
Returns
- AutomationPeer:
An AutomationPeer instance.
OnDeactivated(RoutedEventArgs)
Called when the window loses focus within.
protected virtual void OnDeactivated(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnDragMoved(RoutedEventArgs)
Called after the window has been moved from a drag.
protected virtual void OnDragMoved(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnDragMoving(CancelRoutedEventArgs)
Called before the window is moved from a drag, and can be handled to cancel the drag.
protected virtual void OnDragMoving(CancelRoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | CancelRoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnDragResized(RoutedEventArgs)
Called after the window has been resized from a drag.
protected virtual void OnDragResized(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnDragResizing(CancelRoutedEventArgs)
Called before the window is resized from a drag, and can be handled to cancel the resize.
protected virtual void OnDragResizing(CancelRoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | CancelRoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnGotKeyboardFocus(KeyboardFocusChangedEventArgs)
Occurs when a control within this control's hierarchy gains keyboard focus.
protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | KeyboardFocusChangedEventArgs | The |
OnLocationChanged(RoutedEventArgs)
Called when the window is moved.
protected virtual void OnLocationChanged(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnLostKeyboardFocus(KeyboardFocusChangedEventArgs)
Occurs when a control within this control's hierarchy loses keyboard focus.
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | KeyboardFocusChangedEventArgs | The |
OnOpened(RoutedEventArgs)
Called when the window is opened.
protected virtual void OnOpened(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnStateChanged(RoutedEventArgs)
Called after the window's WindowState property has changed.
protected virtual void OnStateChanged(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnTitleBarDoubleTapped(CancelRoutedEventArgs)
Called when the title-bar is double-tapped, and can be handled to cancel the default action.
protected virtual void OnTitleBarDoubleTapped(CancelRoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | CancelRoutedEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnTitleBarMenuOpening(DockingMenuEventArgs)
Called when the title-bar should display a context menu.
protected virtual void OnTitleBarMenuOpening(DockingMenuEventArgs e)
Parameter | Type | Description |
---|---|---|
e | DockingMenuEventArgs | A |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
Show()
Shows the window.
public void Show()
ToggleWindowState()
Toggles the window's state based on its current state.
public void ToggleWindowState()
Remarks
This method is generally called when the title bar is double-tapped.
Events
Activated
Occurs when the window gains focus within.
Closed
Occurs when the window is about to close.
Closing
Occurs directly after Close() is called, and can be handled to cancel window closure.
public event EventHandler<CancelRoutedEventArgs> Closing
Event Type
Deactivated
Occurs when the window loses focus within.
DragMoved
Occurs after the window has been moved from a drag.
DragMoving
Occurs before the window is moved from a drag, and can be handled to cancel the drag.
public event EventHandler<CancelRoutedEventArgs> DragMoving
Event Type
DragResized
Occurs after the window has been resized from a drag.
DragResizing
Occurs before the window is resized from a drag, and can be handled to cancel the resize.
public event EventHandler<CancelRoutedEventArgs> DragResizing
Event Type
LocationChanged
Occurs when the window is moved.
Opened
Occurs when the window is opened.
StateChanged
Occurs after the window's WindowState property has changed.
TitleBarDoubleTapped
Occurs when the title-bar is double-tapped, and can be handled to cancel the default action.
public event EventHandler<CancelRoutedEventArgs> TitleBarDoubleTapped
Event Type
TitleBarMenuOpening
Occurs when the title-bar should display a context menu.
public event EventHandler<DockingMenuEventArgs> TitleBarMenuOpening
Event Type
Fields
ActivatedEvent
Identifies the Activated routed event. This field is read-only.
public static readonly RoutedEvent ActivatedEvent
CanCloseProperty
Identifies the CanClose dependency property. This field is read-only.
public static readonly DependencyProperty CanCloseProperty
ClosedEvent
Identifies the Closed routed event. This field is read-only.
public static readonly RoutedEvent ClosedEvent
ClosingEvent
Identifies the Closing routed event. This field is read-only.
public static readonly RoutedEvent ClosingEvent
ContextContentProperty
Identifies the ContextContent dependency property. This field is read-only.
public static readonly DependencyProperty ContextContentProperty
ContextContentTemplateProperty
Identifies the ContextContentTemplate dependency property. This field is read-only.
public static readonly DependencyProperty ContextContentTemplateProperty
ContextContentTemplateSelectorProperty
Identifies the ContextContentTemplateSelector dependency property. This field is read-only.
public static readonly DependencyProperty ContextContentTemplateSelectorProperty
CornerRadiusProperty
Identifies the CornerRadius dependency property. This field is read-only.
public static readonly DependencyProperty CornerRadiusProperty
DeactivatedEvent
Identifies the Deactivated routed event. This field is read-only.
public static readonly RoutedEvent DeactivatedEvent
DragMovedEvent
Identifies the DragMoved routed event. This field is read-only.
public static readonly RoutedEvent DragMovedEvent
DragMovingEvent
Identifies the DragMoving routed event. This field is read-only.
public static readonly RoutedEvent DragMovingEvent
DragResizedEvent
Identifies the DragResized routed event. This field is read-only.
public static readonly RoutedEvent DragResizedEvent
DragResizingEvent
Identifies the DragResizing routed event. This field is read-only.
public static readonly RoutedEvent DragResizingEvent
HasCloseButtonProperty
Identifies the HasCloseButton dependency property. This field is read-only.
public static readonly DependencyProperty HasCloseButtonProperty
HasDropShadowProperty
Identifies the HasDropShadow dependency property. This field is read-only.
public static readonly DependencyProperty HasDropShadowProperty
HasIconProperty
Identifies the HasIcon dependency property. This field is read-only.
public static readonly DependencyProperty HasIconProperty
HasMaximizeButtonProperty
Identifies the HasMaximizeButton dependency property. This field is read-only.
public static readonly DependencyProperty HasMaximizeButtonProperty
HasMinimizeButtonProperty
Identifies the HasMinimizeButton dependency property. This field is read-only.
public static readonly DependencyProperty HasMinimizeButtonProperty
HasRestoreButtonProperty
Identifies the HasRestoreButton dependency property. This field is read-only.
public static readonly DependencyProperty HasRestoreButtonProperty
HasTitleBarProperty
Identifies the HasTitleBar dependency property. This field is read-only.
public static readonly DependencyProperty HasTitleBarProperty
IconProperty
Identifies the Icon dependency property. This field is read-only.
public static readonly DependencyProperty IconProperty
IsActiveProperty
Identifies the IsActive dependency property. This field is read-only.
public static readonly DependencyProperty IsActiveProperty
IsCloseButtonVisibleProperty
Identifies the IsCloseButtonVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsCloseButtonVisibleProperty
IsMaximizeButtonVisibleProperty
Identifies the IsMaximizeButtonVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsMaximizeButtonVisibleProperty
IsMaximizedFrameVisibleProperty
Identifies the IsMaximizedFrameVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsMaximizedFrameVisibleProperty
IsMinimizeButtonVisibleProperty
Identifies the IsMinimizeButtonVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsMinimizeButtonVisibleProperty
IsMovingProperty
Identifies the IsMoving dependency property. This field is read-only.
public static readonly DependencyProperty IsMovingProperty
IsReadOnlyProperty
Identifies the IsReadOnly dependency property. This field is read-only.
public static readonly DependencyProperty IsReadOnlyProperty
IsResizingProperty
Identifies the IsResizing dependency property. This field is read-only.
public static readonly DependencyProperty IsResizingProperty
IsRestoreButtonVisibleProperty
Identifies the IsRestoreButtonVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsRestoreButtonVisibleProperty
LeftProperty
Identifies the Left dependency property. This field is read-only.
public static readonly DependencyProperty LeftProperty
LocationChangedEvent
Identifies the LocationChanged routed event. This field is read-only.
public static readonly RoutedEvent LocationChangedEvent
OpenedEvent
Identifies the Opened routed event. This field is read-only.
public static readonly RoutedEvent OpenedEvent
ReadOnlyContextContentTemplateProperty
Identifies the ReadOnlyContextContentTemplate dependency property. This field is read-only.
public static readonly DependencyProperty ReadOnlyContextContentTemplateProperty
ResizeModeProperty
Identifies the ResizeMode dependency property. This field is read-only.
public static readonly DependencyProperty ResizeModeProperty
RestoredBoundsProperty
Identifies the RestoredBounds
dependency property. This field is read-only.
public static readonly DependencyProperty RestoredBoundsProperty
ShadowElevationProperty
Identifies the ShadowElevation dependency property. This field is read-only.
public static readonly DependencyProperty ShadowElevationProperty
StateChangedEvent
Identifies the StateChanged routed event. This field is read-only.
public static readonly RoutedEvent StateChangedEvent
TitleBarDoubleTappedEvent
Identifies the TitleBarDoubleTapped routed event. This field is read-only.
public static readonly RoutedEvent TitleBarDoubleTappedEvent
TitleBarFontWeightProperty
Identifies the TitleBarFontWeight dependency property. This field is read-only.
public static readonly DependencyProperty TitleBarFontWeightProperty
TitleBarMenuOpeningEvent
Identifies the TitleBarMenuOpening routed event. This field is read-only.
public static readonly RoutedEvent TitleBarMenuOpeningEvent
TitleProperty
Identifies the Title dependency property. This field is read-only.
public static readonly DependencyProperty TitleProperty
TopProperty
Identifies the Top dependency property. This field is read-only.
public static readonly DependencyProperty TopProperty
WindowStateProperty
Identifies the WindowState dependency property. This field is read-only.
public static readonly DependencyProperty WindowStateProperty
Inherited Members
- Object.ToString()
- Object.Equals(Object)
- Object.Equals(Object, Object)
- Object.ReferenceEquals(Object, Object)
- Object.GetHashCode()
- Object.GetType()
- Object.MemberwiseClone()
Extension Methods
- FrameworkElementExtensions.AnimateDoubleProperty(String, Double, Double, Double, Nullable<Double>, Nullable<Double>)
- FrameworkElementExtensions.BindToProperty(DependencyProperty, Object, String, BindingMode, IValueConverter, Object)
- FrameworkElementExtensions.BindToProperty(DependencyProperty, Object, DependencyProperty, BindingMode, IValueConverter, Object)
- FrameworkElementExtensions.GetCurrentSize()