WPF C# button click event in code behind -


i have create button in code behind , how write click event? mousedown? ? want detect if button being pressed populate textbox text.

button btn1 = new button(); btn1.content = qhm.option1; sp1.children.add(btn1);  if (btn1.mousedown = true) {    tbox.text = qhm.option1; } 

like that:

button btn1 = new button(); btn1.content = qhm.option1; btn1.click += btn_click; sp1.children.add(btn1);   //separate method private void btn_click(object sender, routedeventargs e) {     tbox.text = qhm.option1; } 

using lambda:

btn1.click += (source, e) => {         tbox.text = qhm.option1; }; 

you can access local variables.


Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -