I am new to c# and has a question about events on a WPF application. I have two events (Button_Click and myslider_ValueChanged) and would like the myslider_ValueChanged to run after Button_Click. I have tried using EventHandler but it both events still run at the same time. Is there an easier way to do this such as a nested event? Any help is appreciated, thanks. I have attached my EventHandler attempt below.
namespace program
{
public partial class MainWindow : Window
{
public event EventHandler _Click;
public event EventHandler _ValueChanged;
protected void On_Click(EventArgs e)
{
if (_Click != null)
{
_Click(this, e);
}
}
protected void On_ValueChanged(EventArgs e)
{
On_Click(EventArgs.Empty);
}
private void Initialize()
{
_Click += new EventHandler(_Click);
_ValueChanged += new EventHandler(_ValueChanged);
_Click += _ValueChanged;
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
//Code here
}
private void myslider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
//Code here
}
You should have myslider_ValueChanged call a different method to perform the work, then call that new method from button_click.
For example: