c# - Take element's parent name, a few levels above -


i have many tabitems in mainwindow.xaml.cs same structures. 1 of them.

<tabitem name="tabfeatured" header="featured" datacontext="{binding templatesfeatured}">             <scrollviewer>                 <itemscontrol name="itemscontrolfeatured" itemssource="{binding}" >                     <itemscontrol.itemspanel>                         <itemspaneltemplate>                             <wrappanel/>                         </itemspaneltemplate>                     </itemscontrol.itemspanel>                     <itemscontrol.itemtemplate>                         <datatemplate>                             <button                                  name="featured"                                 tag="{binding id}"                                 click="button_download_click">                             </button>                         </datatemplate>                     </itemscontrol.itemtemplate>                 </itemscontrol>             </scrollviewer>         </tabitem> 

and c#

private void button_download_click(object sender, routedeventargs e) {     button b = (button)sender;      string buttontag = b.tag.tostring();     string categoryname = b.name.tolower(); } 

how can take tabitem's name of clicked button, can use datacontext.

every tabitem has different context , want it, depends on button's name.

it not clear question trying achieve make assumptions.

i think want datacontext of tabitem button pressed, binding buttons same click event handler.

if on right track of these issues simplified using mvvm pattern. see here description decompose each tabitem content own view , viewmodel.

the overall tabcontrol have own viewmodel, have property each of tabitems (or collection of items). each of these viewmodel , bound content section of each tab item.

you setup data context map between each viewmodel , view, in effect telling wpf, when see viewmodel render view.

when bind each of these buttons binding icommand on viewmodel, happens context of current tab.

this might seem overkill make things simpler in long run.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -