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 : Fenster an einer bestimmten Position öffnen

13.01.2019 (👁5939)


 

 

Wie stellt man ein WPF Window ein, damit dieses beim Öffnen direkt an der Position oder Stelle der Maus plaziert ist?

 

Lösung:

Hierzu direkt in den Event Window_Loaded die obere und linke Position einstellen

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

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

 

 

 

 

Lösung:

Im Window, welches geöffnet wird, muss man die .Top und .Left Eigenschaft auf den Wert der Mouse-Position setzen

 

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 () >--------

}

 

 

 

In xaml des Windows folgenden Event aktivieren

WindowStartupLocation="Manual"  Loaded="Window_Loaded" 

 

 

Xaml des Fensters

<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" 

        >