Here is a code-behind version:
1. UI/XAML
<Window x:Class="WpfControlHost.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ContentControl x:Name="ContentControl" />
<Button Grid.Row="1"
HorizontalAlignment = "Center"
VerticalAlignment = "Center"
Padding="20 10"
Margin="10"
Content="SWAP"
Click="ButtonBase_OnClick"/>
</Grid>
</Window>
2. Code-behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SwapControls();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
SwapControls();
}
private void SwapControls()
{
ContentControl.Content = ContentControl.Content?.GetType()
== typeof(UserControl1)
? new UserControl2()
: new UserControl1();
}
}