Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

WPF: Open Window at an position

13.01.2019 (πŸ‘232)


 

 

How do you set a WPF Window so that it is placed directly at the position or place of the mouse when opening?

 

Solution:

To do this directly in the event Window _ Loaded adjust the top and left position

 

    this.Top = Mouse.GetPosition(null).Y;

    this.Left = Mouse.GetPosition(null).X;

 

 

 

 

Solution:

In the window, which is opened, you have to use the. Top and. Left property to put the value of the mouse position

 

private void Window_Loaded(object sender, RoutedEventArgs e)

{

    //----< Window_Loaded () >--------

 

    //< Window_Position >

    //*TopLeft-Corner to Mouse-Position

    this.Top = Mouse.GetPosition(null).Y;

    this.Left = Mouse.GetPosition(null).X;

    //</ Window_Position >

    //----</ Window_Loaded () >--------

}

 

 

 

Activate Event in xaml of Windows Following

 

WindowStartupLocation="Manual"  Loaded="Window_Loaded" 

 

 

Xaml of the window

 

<Window x:Class="Schichtplaner.PU_Schichtplan_Mitarbeiter"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:Schichtplaner"

        mc:Ignorable="d" FontSize="12pt"

        Title="Mitarbeiter wΓ€hlen" Height="450" Width="400" WindowStartupLocation="Manual"  Loaded="Window_Loaded" 

        WindowStyle="ToolWindow" 

        >