Reputation: 2967
I have a WPF DataGrid with some styling, properties and events.
I want to override its OnMouseLeftButtonDown and OnMouseLeftButtonUp events to do something.
How do I do this?
Thanks!
Upvotes: 2
Views: 1431
Reputation: 137148
Create your own class based on DataGrid
and add the event handlers you need. Then in your XAML use your DataGrid
rather than the "normal" one.
public class MyDataGrid : DataGrid
{
// Your overrides here
}
And in XAML:
<Window x:Class="MyProject.MyNamespaceMyClass"
....
xmlns:local="clr-namespace:MyProject.MyNamespace">
....
<local:MyDataGrid ... />
....
</Window>
Upvotes: 4
Reputation: 45096
Add an event and in the event put e.Handled = true
if you want to mark it as handled. Be aware ordering of event bubbling is different for down compared to up and there is a preview. Or you can override the method. I am just more comfortable with events. If you override the down event then the up event might not fire - not sure but it is something to test for.
Upvotes: 0