c# - Passing data between WPF windows using events with custom delegate type -
i'm passing text sub window main window using events , delegates i'm getting following error:
the type or namespace name 'textupdateeventargs' not found (are missing using directive or assembly reference?)
can me this?
mainwindow.cs code
namespace passing_data_btw_events { /// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window { public mainwindow() { initializecomponent(); } private void menuitem_click_1(object sender, eventargs e) { subwindow f = new subwindow(); f.textupdated += new subwindow.textupdatehandler(textform_buttonclicked); f.show(); } // handles event subwindow public void textform_buttonclicked(object sender, textupdateeventargs e) { // update window values event args //txtname.text = e.name; treeviewitem child = new treeviewitem(); child.header = e.name; treeview2.items.add(child); } } } subwindow.cs code
namespace passing_data_btw_events { public partial class subwindow : window { //adding delegate public delegate void textupdatehandler(object sender, textupdateeventargs e); // add event of delegate type public event textupdatehandler textupdated; public subwindow() { initializecomponent(); } public void add_click(object sender, eventargs e) { // button click event handler raise // event can intercepted listeners // read textboxes , set member // variables string newtextbox = nametextbox.text; // instance event args , pass each value textupdateeventargs args = new textupdateeventargs(newtextbox); // raise event updated arguments textupdated(this,args); // this.close(); } public class textupdateeventargs : system.eventargs { public string mname; public textupdateeventargs(string sname) { this.mname = sname; } public string name { { return mname; } } } } }
textupdatehandler , textupdateeventargs nested types because declared inside subwindow class. referred delegate correctly using subwindow.textupdatehandler. same event type:
public void textform_buttonclicked(object sender, subwindow.textupdateeventargs e) { }
Comments
Post a Comment