c# - Removing a usercontrol by clicking a button on it -
i have gridview shows items in it. each item has edit button it, pressing edit button loads usercontrol next item. usercontrol has close button it, pressing close button removes usercontrol.
blue color rectangles represent items in gridview. on clicking pink add button red color usercontrol loads up. on clicking close button on red rectangle should remove red color item , revert original state. have added usercontrol using template selector , working fine. close button not remove it. have tried following approach removing :
(gridview)this.parent).items.remove(this);
on adding breakpoint , checking found this.parent null. stuck.how proceed? using c#, xaml, winrt, visual studio 2012
if need work visual tree, try this:
var _parent = visualtreehelper.getparent(sender usercontrol) gridview; _parent.items.remove(sender usercontrol);
but removing items gridview should done manipulating observablecollection bound itemssource of gridview in viewmodel. not this, probably...