Docking Windows on desktop programmatically from .net core 5

Zoidboom 21 Reputation points
2021-01-23T16:18:48.243+00:00

Hi,

I have a main wpf window that spawns off a ekstra tool window. I use the windows button and arrows to place them maximized to the left and right respectively on desktop. Like the xaml WindowsState="Maximized", is there a way programmatically to dock the windows to the left and right of the desktop.

Thanks.
Z

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,695 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,470 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,135 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 82,316 Reputation points
    2021-01-23T20:00:31.067+00:00

    A way is to simulate the Windows Key

    For example, with Left Arrow => (tested on Windows 10 1909, WPF .NET 5.0)

    keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0);
    keybd_event(VK_LEFT, 0, 0, 0);
    keybd_event(VK_LEFT, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
    

    Declarations :

    [DllImport("User32.dll", SetLastError = true)]
    public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
    
    public const int KEYEVENTF_EXTENDEDKEY = 0x0001;
    public const int KEYEVENTF_KEYUP = 0x0002;
    
    public const int VK_LWIN = 0x5B;
    public const int VK_LEFT = 0x25;
    public const int VK_UP = 0x26;
    public const int VK_RIGHT = 0x27;
    public const int VK_DOWN = 0x28;
    
    0 comments No comments

  2. DaisyTian-1203 11,616 Reputation points
    2021-01-25T05:53:47.343+00:00

    You can install Extended.Wpf.Toolkit in your Nuget package manager and add xmlns:avalon="http://schemas.xceed.com/wpf/xaml/avalondock" to your xaml. Then you can use it like below:

    <Grid>  
            <avalon:DockingManager>  
                <avalon:DockingManager.Theme>  
                    <avalon:MetroTheme></avalon:MetroTheme>  
                </avalon:DockingManager.Theme>  
                <avalon:LayoutRoot>  
                    <avalon:LayoutPanel Orientation="Horizontal">  
                        <avalon:LayoutPanel Orientation="Vertical">  
                            <avalon:LayoutAnchorablePaneGroup DockMinHeight="180" FloatingHeight="180">  
                                <avalon:LayoutAnchorablePane x:Name="panelBottom">  
                                    <avalon:LayoutAnchorable Title="Bottom1"></avalon:LayoutAnchorable>  
                                    <avalon:LayoutAnchorable Title="Bottom2"></avalon:LayoutAnchorable>  
                                    <avalon:LayoutAnchorable Title="Bottom3"></avalon:LayoutAnchorable>  
                                </avalon:LayoutAnchorablePane>  
                            </avalon:LayoutAnchorablePaneGroup>  
                        </avalon:LayoutPanel>  
                    </avalon:LayoutPanel>  
                </avalon:LayoutRoot>  
            </avalon:DockingManager>  
        </Grid>  
    

    And the result picture is:
    60044-capture.png
    Is it what you want to implement? If it is not, could you give me more description about your question?


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments