回答編集履歴

1

質問文変更につき回答内容を変更しました。

2016/12/08 04:40

投稿

twyujiro15
twyujiro15

スコア217

test CHANGED
@@ -1,37 +1,23 @@
1
- ```XAML
1
+ 自分なら A と B をあらかじめ配置、Visibility.Collapsed にしておいて、
2
2
 
3
- <Window x:Class="SampleApp.MainWindow"
3
+ ボタンクリックなどのタイミングで Style.Triggers で
4
4
 
5
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6
-
7
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
8
-
9
- xmlns:local="clr-namespace:SampleApp"
10
-
11
- Title="MainWindow" Height="100" Width="200">
12
-
13
- <Grid>
14
-
15
- <Button Content="Click me." />
16
-
17
- </Grid>
5
+ Visibility を入れ替えるようにします。
18
-
19
- </Window>
20
-
21
- ```
22
6
 
23
7
 
24
8
 
25
- プレフィックスってもしかして上記コード
9
+ A および B 内容が大きい場合は
26
10
 
27
- 「xmlns:local="clr-namespace:SampleApp"」の「local」や「SampleApp」のことでょうか。
11
+ MainWindow のデータコンテキストに CurrentViewModel みたいなプロパティを用意
28
12
 
29
- ういったことは動的はできせん
13
+ A と B れぞれ ViewModel を用意し
30
14
 
15
+ ContentControl の Content プロパティに CurrentViewModel をバインドし、
31
16
 
17
+ ボタンクリックのコマンドから CurrentViewModel を A から B、B から A 用のものに入れ替えます。
32
18
 
33
- らくこ疑問何かの機能実現しようとしてこアイデアにたどり着いたんだと思いますが
19
+ CurrentViewModel をバインドされた ContentControl はそのままで UI 表示できない
34
20
 
35
- その実現しようとしている機能そのもの質問たほうが
21
+ App.Resources などに DataTemplate 定義
36
22
 
37
- 解決やすいと思います。
23
+ A の ViewModel のときは A、B の ViewModel のときは B が表示されるようにします。