I have a CustomControl
with some elements and a Button
.
I want to remove/close/dispose the CustomControl
when the Button
clicked.
I tried to get the parent of the element when the Button
is clicked but all I get is crush.
My CustomControl
is TabItem
and I want to remove it from the TabControl
, so to get the TabControl
I use the following code (and it crushes):
TabControl parent = VisualTreeHelper.GetParent(this) as TabControl;
What am I doing wrong? Maybe my approach is wrong? If so, how can I remove/close/dispose the TabItem
when the Button
is clicked?
Thanks