wpf - Access Parent Data Context using Code -


if want bind parent data context data using xaml , write following:

<usercontrol> <radgridview x:name="parentgrid">    <radgridview.rowdetailstemplate>          <datatemplate>                <radgridview x:name="childgrid" itemssource="{binding datacontext.result, relativesource={relativesource ancestortype={x:type usercontrol}}}"                                        />   </radgridview.rowdetailstemplate>  </radgridview> </usercontrol> 

but how do using code considering code in different class , let's attached propertey . able access sender , args following:

 parentgrid.loadingrowdetails += (sender, args) =>                     {                         radgridview gridview = args.detailselement.findname("childgrid") radgridview;                          if (gridview != default(radgridview))                         {                             gridview = //should able access datacontext.result                         }                       }; 

since you're looking specific type can walk visual tree using method findvisualparent here: how can find wpf controls name or type?

at point you've done equivalent of relativesource part of binding , can access datacontext on returned object.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -