Skip to content

peterGdot/Pyther.WindowX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pyther.WindowX

Window extension class for Win UI 3 Applications.

This simple class extends the Microsoft.UI.Xaml.Window class with the following properties you may know from WPF, but are currently missing in Win UI 3:

  • Title - the window title
  • Icon - the window icon (from a resource, using the application icon or from an external file path)
  • Width - the window width
  • Height - the window height
  • WindowStartupLocation - the window startup location (Manual or CenterScreen)
  • WindowState - the window state (Normal, Minimized or Maximized)
  • ResizeMode - the resize modes (NoResize, CanMinimize, CanResize or CanResizeWithGrip)
  • WindowStyle - the window sytle (None, SingleBorderWindow, ThreeDBorderWindow or ToolWindow)

All properties are made available in the XAML layout files. It will also take DPI scaling into account.

To use it in your code, simple inherit from the Pyther.WindowX.WindowX class.

    public sealed partial class MainWindow : Pyther.WindowX.WindowX
    {
        public MainWindow() {
            this.InitializeComponent();
        }
    }

and modify your XAML root tag

<winX:WindowX
    ...
    xmlns:winX="using:Pyther.WindowX"
    ...
    Title="A Pyther.WindowX Example"
    Icon="Demo.Assets.window.ico"
    Width="800"
    Height="500"
    WindowStartupLocation="CenterScreen"
    WindowStyle="ToolWindow"
    >
    ...
</winX:WindowX>

that's it!

In addition to XAML, you can of course set all properties by code:

    public sealed partial class MainWindow : Pyther.WindowX.WindowX
    {
        public MainWindow() {
            this.InitializeComponent();

            this.Title = "A Pyther.WindowX Example";
            this.Icon = "Demo.Assets.window.ico";
            this.Width = 800;
            this.Height = 500;
            this.WindowStartupLocation = Pyther.WindowX.WindowStartupLocation.CenterScreen;
            this.WindowStyle = Pyther.WindowX.WindowStyle.ToolWindow;
        }
    }

This code requires PInvoke and System.Drawing.Common (if you want to use the Icon property) to run.

You will find all the required source in Pyther.WindowX/WindowX.cs.

Some notes about the Icon property

The are 4 ways of using an icon:

  1. embedded resource - This is the default way to include an icon into your application. You add them as an embedded(!) resource and access it using the resource resolve syntax "namespace.path.file" like Icon="Demo.Assets.window.ico".
  2. using the application icon - If you has set an application icon, you can simply (re)use it with Icon="application" or Icon="app".
  3. using relative file path - To load an icon from an external file relative to your application directory, you can use the rel: prefix like Icon="rel:media\window.ico".
  4. using absolute file path - And finally you can also load from an external absolute file path using the abs: prefix like Icon="abs:E:\Projects\Pyther\WindowX\window.ico".

It's also worth to mention, that no Exception will be thrown, if setting an icon failed.

About

Window extension class for Win UI 3 Applications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages