Table of Contents

Class WindowFrameworkElement

Namespace
WindowSill.API
Assembly
WindowSill.API.dll

This class is used a workaround for this issue: https://github.com/microsoft/microsoft-ui-xaml/issues/4966 In WinUI, Window isn't a Control. This cause the source code generator to fail when trying to generate the code a x:Bind that use a Converter. It also causes ViewState to not work at all. We can use this class as a root element that is a UserControl and use it as the x:Bind source while exposing its associated window under the hood.

public class WindowFrameworkElement : UserControl, IEquatable<DependencyObject>, IAnimationObject, IVisualElement, IVisualElement2, IEquatable<UIElement>, IEquatable<FrameworkElement>, IEquatable<Control>, IWinRTObject, IUnmanagedVirtualMethodTableProvider, IDynamicInterfaceCastable, IEquatable<UserControl>
Inheritance
WindowFrameworkElement
Implements
IWinRTObject
Derived
Inherited Members
Extension Methods

Constructors

WindowFrameworkElement()

Initializes a new instance of the WindowFrameworkElement class.

public WindowFrameworkElement()

Properties

UnderlyingWindow

Gets the underlying WinUIEx.WindowEx instance associated with this framework element.

public WindowEx UnderlyingWindow { get; }

Property Value

WindowEx

Methods

ShowAndCenter(UIElement?, double, double)

Displays the window and centers it on the same monitor as the specified UI element, using the provided default size if available.

public void ShowAndCenter(UIElement? element, double defaultWidth = NaN, double defaultHeight = NaN)

Parameters

element UIElement

The UI element whose monitor will be used to determine the centering location. If null or if the monitor cannot be determined, the window is centered on the primary screen.

defaultWidth double

The desired width of the window in device-independent units. If not specified or set to NaN or 0, the window's current or minimum width is used.

defaultHeight double

The desired height of the window in device-independent units. If not specified or set to NaN or 0, the window's current or minimum height is used.

Remarks

If the monitor associated with the specified element cannot be determined, the window falls back to centering on the primary screen. The method ensures the window is activated and brought to the foreground after displaying.