xaml 中的鼠标位置 - wpf
是否可以将鼠标的位置指定为 XAML 中 Command 的 Parameter 属性的值。像下面这样:
<UserControl.ContextMenu>
<ContextMenu>
<MenuItem Header="Create Link"
Command="{Binding CreateLink}"
CommandParameter="{Binding Mouse.Position}" >
</MenuItem>
</ContextMenu>
</UserControl.ContextMenu>
Is it possible to specify the position of the mouse as the value of the Parameter property of a Command in XAML. Something like the following:
<UserControl.ContextMenu>
<ContextMenu>
<MenuItem Header="Create Link"
Command="{Binding CreateLink}"
CommandParameter="{Binding Mouse.Position}" >
</MenuItem>
</ContextMenu>
</UserControl.ContextMenu>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 WPF 中,没有 Mouse.Position。如果您查看 鼠标类成员,最接近的是Mouse.GetPosition,返回相对于某个 UI 元素的位置。
我建议使用 UI 元素本身作为命令参数,并让您的命令调用
Mouse.GetPosition
来检索位置(如果您的 DataContext 出于某种原因需要这样做)。In WPF, there is no Mouse.Position. If you look at the Mouse class members, the closest thing is Mouse.GetPosition, which returns the position relative to some UI element.
I would recommend using the UI element itself as the Command Parameter, and having your Command call
Mouse.GetPosition
to retrieve positioning, if this is required in your DataContext for some reason.是的,如果您希望以编程方式执行此操作,则可以使用 PointToScreen() 以及 Mouse.GetPosition(this) 来获取绝对鼠标点。如果您需要以编程方式而不是在 XAML 中执行此操作,请查看此内容,
http://ivolo.mit.edu/post/WPF-Mouse-and-Point-Acrobatics.aspx
Yeah, if you were looking to do it programatically, you can use the PointToScreen() as well as the Mouse.GetPosition(this) to get the absolute mouse point. Take a look at this should you need to do this programatically, not in XAML,
http://ivolo.mit.edu/post/WPF-Mouse-and-Point-Acrobatics.aspx