The Parent property refers to the logical tree, and the docs state that "the parent can be empty when the element was created, but not tied to the logical tree, which ultimately connects to the root element of the page level, or the application object." For example, the root element of a DataTemplate created in a ListBox has a null parent.
Try using VisualTreeHelper.GetParent . The visual tree is a lower-level view of how WPF elements are organized, and gives you access to all the extra βbitsβ that can be added to templates. For example, a call to VisualTreeHelper.GetParent on the root DataTemplate created in the ListBox returns a ContentPresenter .
Please note that just because you can get the parent visual does not necessarily mean that you can delete it. Some elements, such as panels, provide methods for this. But if the item you find is part of, say, CheckBox , I donβt think you can remove it.
If you can provide a little more context for what you are trying to achieve by moving controls around the visual tree, people can offer more specific recommendations or alternative approaches.
source share