twyujiro15さんの回答の補足です。
ちょっと難易度が高いかなと思うので…詳しくはContentControl WPFで検索してみてください。
データバインディングは知っている想定で部分的なコードを共有します。
知らない場合はこちらも検索してみてください。
XAMLに以下のように記述すればcomponent:Aとcomponent:Bを差し替えることができます。
※全文ではなく部分的な抜き出しです
CSharp
1<!-- ContentControlがcomponentを保持します -->
2<ContentControl Content="{Binding Target}">
3 <ContentControl.Resources>
4 <!-- バインディングされたTargetの型と表示コンテンツを関連付けることができます。 -->
5 <DataTemplate DataType="{x:Type local:AViewModel}">
6 <component:A />
7 </DataTemplate>
8 <DataTemplate DataType="{x:Type local:BViewModel}">
9 <component:B />
10 </DataTemplate>
11 </ContentControl.Resources>
12</ContentControl>
13<Button HorizontalAlignment="Left" VerticalAlignment="Top"
14 Content="ボタン" Command="{Binding ChangeTargetCommand}" />
CSharp
1public class Presenter : INotifyPropertyChanged
2{
3 public event PropertyChangedEventHandler PropertyChanged;
4
5 public object Target
6 {
7 get
8 {
9 return _Target;
10 }
11 set
12 {
13 if (_Target != value)
14 {
15 _Target = value;
16 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Target)));
17 }
18 }
19 }
20 private object _Target = new AViewModel();
21
22 // Targetプロパティのモデルを、AViewModelからBViewModelに変更するだけのコマンド
23 public ICommand ChangeTargetCommand
24 {
25 get
26 {
27 return _ChangeTargetCommand = _ChangeTargetCommand ??
28 new DelegateCommand(() => Target = new BViewModel());
29 }
30 }
31 private ICommand _ChangeTargetCommand;
32}