views:

692

answers:

2

Hi all

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>
+1  A: 

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.

Reed Copsey
+1  A: 

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

Ilya