![]() The sample project can be download, wpfdatagridmouseclicks, changing the file extension from. We just have to look at the Position property in the class. Putting it all together, this blog post has a small smaple application which displays the header index and value, or cell's row/column indices and value in response to a right mouse click: The process to get your mouse coordinates is actually pretty simple. This originated for the requirement of a Rating Control in WPF, (the star thing, well we have RadioButtonList in CodeProject pages). How do you get the current mouse screen coordinates in WPF (mouse. Firstly, we add an event handler for the mouse click in our code-behind:Ĭ#: private void DataGrid_MouseRightButtonUp ( object sender, MouseButtonEventArgs e ) Because of this ControlClick probably wont work in most modern web browsers for. Note that you will have to use Add-Type if running from the console 1 ::Position Note the X and Y coordinates above. I used the Win32 approach to get the correct mouse position after the delay and use this to get the current TreeViewItem under the mouse by using a hit test. ![]() Let's say for example you wanted to find the DataGrid item (cell, row, header) that was clicked when the right mouse button is released. The process to get your mouse coordinates is actually pretty simple. In order to implement this behaviour you have to understand the visual tree of the DataGrid and how it can be navigated. To figure out the relative coordinates of controls in your app, simply use TranslatePoint like so to get the coordinates: Code Snippet TranslatePoint ( new Point (0.0, 0.0), referenceElement) To get the coordinates of the upper left of your control relative to 'referenceElement'. You might expect this information to be readily available in the form of events, after all, the Windows Forms DataGridView has CellClicked and ColumnHeaderMouseClick events (among many others). A fairly common task when working with DataGrid is detecting which row, or cell a user has clicked on, or whether they clicked a column header. Should you have any questions or need assistance from a member of our team, write to us at. ![]() The WPF DataGrid is a very flexible tool, however in its current state certain simple tasks can prove to be rather tricky. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible. When the user moves the mouse over the image, I would like to determine the coordinates of the mouse with respect to the original image (before stretching/cropping that occurs when it is displayed in the control), and then do something with those coordinates (update the image).
0 Comments
Leave a Reply. |