C# 我可以使用WPF从DomEventArgs获取鼠标坐标吗

C# 我可以使用WPF从DomEventArgs获取鼠标坐标吗,c#,wpf,dotnetbrowser,C#,Wpf,Dotnetbrowser,目标是向用户指示InputSimulator.SimulateMouseMoveEvent。所以,我需要在每次移动事件中获得文档的位置,我使用EventListener和DOMEventType.OnMouseMove。但是如果DOMEventArgs包含MouseEvent属性,则无法获取 有可能按我的方式做吗?有什么解决方案可以做到这一点吗?出于所述目的,您需要在JavaScript端订阅上述事件,并使用JS-.NET桥 此代码示例演示如何使用mousemove事件获取鼠标位置: XAML

目标是向用户指示
InputSimulator.SimulateMouseMoveEvent
。所以,我需要在每次移动事件中获得文档的位置,我使用
EventListener
DOMEventType.OnMouseMove
。但是如果DOMEventArgs包含MouseEvent属性,则无法获取


有可能按我的方式做吗?有什么解决方案可以做到这一点吗?

出于所述目的,您需要在JavaScript端订阅上述事件,并使用JS-.NET桥

此代码示例演示如何使用mousemove事件获取鼠标位置: XAML

<Window x:Class="WpfApplication33.MainWindow"
        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:wpf="clr-namespace:DotNetBrowser.WPF;assembly=DotNetBrowser"
        xmlns:local="clr-namespace:WpfApplication33"
        mc:Ignorable="d"
        Title="MainWindow" Height="600" Width="900">
    <Grid Name="mainLayout">
        <Grid.RowDefinitions>
            <RowDefinition Height="24*"/>
            <RowDefinition Height="295*"/>
        </Grid.RowDefinitions>
        <Button x:Name="button" Content="Button" Grid.Row="0" Click="button_Click"/>
        <wpf:WPFBrowserView Name="browserView" Grid.Row="1"/>
    </Grid>
</Window>

C#

使用系统;
使用系统诊断;
使用System.Windows;
使用dotnebrowser;
使用dotnebrowser.DOM;
使用dotnebrowser.DOM.Events;
命名空间WpfApplication33
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
browserView.Browser.FinishLoadingFrameEvent+=(s,e)=>
{
if(e.IsMainFrame)
{
JSValue window=e.Browser.executejavascriptanderturnvalue(“window”);
SetProperty(“CoordinateObject”,新的CoordinateObject());
//此代码仅通知已触发onmousemove事件。
//它无法返回当前鼠标位置。
//DOMDocument document=browserView.Browser.GetDocument();
//DOMELENT documentElement=document.documentElement;
//DOMEventHandler eventHandler=(发送方,参数)=>
//    {
//Debug.WriteLine(“OnMouseMove被激发”);
//    };
//documentElement.AddEventListener(DOMEventType.OnMouseMove,eventHandler,false);
}
};
browserView.Browser.ScriptContextCreated+=(发件人,参数)=>
{
args.Browser.ExecuteJavaScript(@)
document.onmousemove=getMouseXY;
函数getMouseXY(e){
协调对象鼠标位置(e.pageX,e.pageY);
}");
};
browserView.Browser.LoadURL(“google.com”);
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
browserView.InputSimulator.SimulateMouseMoveEvent(200150);
}
}
内部类协调对象
{
公共无效鼠标位置(点X、点Y)
{
Debug.WriteLine(“X=“+X+”Y=“+Y”);
}
}
}

出于上述目的,您需要在JavaScript端订阅上述事件,并使用JS-.NET网桥

此代码示例演示如何使用mousemove事件获取鼠标位置: XAML

<Window x:Class="WpfApplication33.MainWindow"
        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:wpf="clr-namespace:DotNetBrowser.WPF;assembly=DotNetBrowser"
        xmlns:local="clr-namespace:WpfApplication33"
        mc:Ignorable="d"
        Title="MainWindow" Height="600" Width="900">
    <Grid Name="mainLayout">
        <Grid.RowDefinitions>
            <RowDefinition Height="24*"/>
            <RowDefinition Height="295*"/>
        </Grid.RowDefinitions>
        <Button x:Name="button" Content="Button" Grid.Row="0" Click="button_Click"/>
        <wpf:WPFBrowserView Name="browserView" Grid.Row="1"/>
    </Grid>
</Window>

C#

使用系统;
使用系统诊断;
使用System.Windows;
使用dotnebrowser;
使用dotnebrowser.DOM;
使用dotnebrowser.DOM.Events;
命名空间WpfApplication33
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
browserView.Browser.FinishLoadingFrameEvent+=(s,e)=>
{
if(e.IsMainFrame)
{
JSValue window=e.Browser.executejavascriptanderturnvalue(“window”);
SetProperty(“CoordinateObject”,新的CoordinateObject());
//此代码仅通知已触发onmousemove事件。
//它无法返回当前鼠标位置。
//DOMDocument document=browserView.Browser.GetDocument();
//DOMELENT documentElement=document.documentElement;
//DOMEventHandler eventHandler=(发送方,参数)=>
//    {
//Debug.WriteLine(“OnMouseMove被激发”);
//    };
//documentElement.AddEventListener(DOMEventType.OnMouseMove,eventHandler,false);
}
};
browserView.Browser.ScriptContextCreated+=(发件人,参数)=>
{
args.Browser.ExecuteJavaScript(@)
document.onmousemove=getMouseXY;
函数getMouseXY(e){
协调对象鼠标位置(e.pageX,e.pageY);
}");
};
browserView.Browser.LoadURL(“google.com”);
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
browserView.InputSimulator.SimulateMouseMoveEvent(200150);
}
}
内部类协调对象
{
公共无效鼠标位置(点X、点Y)
{
Debug.WriteLine(“X=“+X+”Y=“+Y”);
}
}
}