'How to do the action only once on two events?
I'm on a C# WPF application, I have a HOME button, on this button I currently have a StylusButtonDown event with actions in front. I want to have a second PreviewMouseLeftButtonDown event on this same button but not have to write the actions twice.
It is possible to write a method and then call this method in both actions but it is not optimal.
Is it possible to create a button that when pressing PreviewMouseLeftButtonDown, does exactly as pressing the StylusButtonDown?
Here's what I don't want to do:
private void BP_31N00_StylusButtonUp(object sender, StylusButtonEventArgs e)
{
ModifyManualVelocityApparence(ref BP_31N00, true);
ModifyManualVelocityApparence(ref BP_31N01, fallse);
ModifyManualVelocityApparence(ref BP_32N04, false);
ModifyManualVelocityApparence(ref BP_32N05, false);
ModifyManualVelocityApparence(ref BP_32N06, false);
ModifyManualVelocityApparence(ref BP_84J01, false);
ModifyManualVelocityApparence(ref BP_86J01, false);
ModifyManualVelocityApparence(ref BP_87J01, false);
ModifyManualVelocityApparence(ref BP_EtherCATNetwork, false);
FRM_ParameterChannel.Content = page31N00;
actualPage = 0;
}
private void BP_31N00_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
ModifyManualVelocityApparence(ref BP_31N00, true);
ModifyManualVelocityApparence(ref BP_31N01, fallse);
ModifyManualVelocityApparence(ref BP_32N04, false);
ModifyManualVelocityApparence(ref BP_32N05, false);
ModifyManualVelocityApparence(ref BP_32N06, false);
ModifyManualVelocityApparence(ref BP_84J01, false);
ModifyManualVelocityApparence(ref BP_86J01, false);
ModifyManualVelocityApparence(ref BP_87J01, false);
ModifyManualVelocityApparence(ref BP_EtherCATNetwork, false);
FRM_ParameterChannel.Content = page31N00;
actualPage = 0;
}
Solution 1:[1]
Since the code is exactly the same and it seems like you don't have to access external attributes you can just connect 2 buttons with the same onClick Method, just go select the button -> properties -> onClick -> and then select the same onClick method from the dropDown menu in the 2 buttons
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sMuLe |
