I have a WPF UserControl (bound to a ViewModel) which has elements such as a textbox and a button. Once the button is pressed, the UserControl is no longer needed.
The ViewModel has no knowledge of the UserControl’s parent (which itself is a Grid on a UserControl).
<UserControl x:Class="Example.UserControlExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
<Grid>
<Button Command="{Binding ButtonClickDoStuff}"/>
</Grid>
</UserControl>
I know I can hide the UserControl, but I don’t need to use it again so would prefer to remove than hide.
- How do I get the View to remove itself from the parent?
- Is there a property on the View that I can bind to?
I have read these Q&As but all the answers are using C# (presumably in the code behind):
- Causing a UserControl to remove itself (WPF)
- How can I remove a parents child control through the child in WPF/XAML?
- Disconnecting an element from any/unspecified parent container in WPF