How to Move Window to Left or Right side of screen in winui 3?

Mahdi Hosseini 135 Reputation points
2023-12-17T20:05:44.6333333+00:00

i want to create a window in Left or Right side of a screen in winui 3

i used following codes:

var width = DisplayArea.Primary.WorkArea.Width;
var height = DisplayArea.Primary.WorkArea.Height;
var x = DisplayArea.Primary.WorkArea.X;
var y = DisplayArea.Primary.WorkArea.Y;

AppWindow.MoveAndResize(new Windows.Graphics.RectInt32
{
    Height = height,
    Width = 340,
    X = x,
    Y = y
});

i can see that my window is created in Left side of screen, but i dont know how to move my window to Right side of screen.

i tried to use:

X = x -340

but did not work if i use - window go to left side again and for going to right i should use + but i dont know how to calcualte currect value.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
747 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,574 questions
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 12,151 Reputation points Microsoft Vendor
    2023-12-18T01:59:52.19+00:00

    The distance between Left and Right side of screen is (DisplayArea.Primary.WorkArea.Width - 340).

    move my window to Right side of screen: x+(width-340);

    And then move my window to Left side of screen: x-(width-340);

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful