Versuchen Sie dieses Beispiel für WPF. Durch Drücken der Geben Sie Schlüssel ein Popup
Fenster im Voraus erhalten die Koordinaten des Mauszeigers.
XAML
<Window x:Class="OpenWindowForCursor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
WindowStartupLocation="CenterScreen"
PreviewKeyDown="Window_PreviewKeyDown">
<Grid>
<Popup Name="PopupWindow"
Placement="Relative"
IsOpen="False"
StaysOpen="False">
<Border Width="100"
Height="100"
Background="AntiqueWhite">
<Label Content="Test" />
</Border>
</Popup>
</Grid>
</Window>
Code-behind
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
PopupWindow.IsOpen = true;
var point = Mouse.GetPosition(Application.Current.MainWindow);
PopupWindow.HorizontalOffset = point.X;
PopupWindow.VerticalOffset = point.Y;
}
}
}
Edit: An easier solution
können Sie einstellen, nur Placement="Mouse"
für Popup
statt Koordinaten der Maus erhalten: sehr viel
XAML
<Grid>
<Popup Name="PopupWindow"
Placement="Mouse"
IsOpen="False"
StaysOpen="False">
<Border Width="100"
Height="100"
Background="AntiqueWhite">
<Label Content="Test" />
</Border>
</Popup>
</Grid>
Code-behind
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
PopupWindow.IsOpen = true;
}
}
}
danke !! – JanivZ