c# - Dynamically add Children to WPF UserControl and Handle its events from WinForm -
i have simple wpf usercontrol called "xnavpanel" contains panel. added control winform using "elementhost". have wpf usercontrol called "mainmenubutton" contains textblock.
from winform; add many "mainmenubutton" in "xnavpanel" dynamically in runtime. have method loop on datatable rows , foreach row adding "mainmenubutton" "xnavpanel" , add event handler each "mainmenubutton".
the problem is; controls doesn't invoke handlers!
public static void fillmenu(xnavpanel navpanel, datatable items) { navpanel.mainpanel.children.clear(); //mainpanel panel inside usercontrol mainmenubutton menuitem; foreach (datarow dr in items.rows) { menuitem = setmenuitem(dr); navpanel.mainpanel.children.add(menuitem); } } static mainmenubutton setmenuitem(datarow dr) { mainmenubutton menuitem = new mainmenubutton(); menuitem.name = "mi_" + dr["formname"].tostring(); menuitem.menuname.text = dr["name"].tostring(); //menuname txblock inside usercontrol menuitem.mouseup += new system.windows.input.mousebuttoneventhandler(menuitem_mouseup); //menuitem.mouseup += ((sender, e) => messagebox.show((sender mainmenubutton).name)); return menuitem; } static void menuitem_mouseup(object sender, system.windows.input.mousebuttoneventargs e) { messagebox.show((sender mainmenubutton).name); }
i found problem
code in question working 100%
problem in else not included in code.
Comments
Post a Comment