0
我有一個主窗口來託管兩個視圖(用戶控件)。一個是UserControl1
,另一個是UserControl2
,在切換系統之後。使用MVVM在WPF中加載用戶控件後啓動視圖(窗口)
UserControl1
先加載然後視圖可以切換。我希望在加載UserControl1
後啓動一個窗口。
我使用消息傳遞模式啓動視圖並在app.xaml
或MainView.xaml
中註冊視圖。
我該如何繼續?
的XAML我的MainView:
<Window x:Class="CustomListView.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CustomView="clr-namespace:CustomListView"
Title="MainView"
Width="300"
Height="300">
<Window.InputBindings>
<CustomView:RelayKeyBinding Key="F12" CommandBinding="{Binding Path=Toggle}"></CustomView:RelayKeyBinding>
</Window.InputBindings>
<Window.Resources>
<DataTemplate x:Key="ExecutionView">
<CustomView:ExecutionView />
</DataTemplate>
<DataTemplate x:Key="ConfigView">
<CustomView:ConfigView />
</DataTemplate>
<Style x:Key="mainContentControlStyle"
TargetType="{x:Type ContentControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Mode}"
Value="1">
<Setter Property="ContentTemplate" Value="{StaticResource ResourceKey=ConfigView}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Mode}"
Value="0">
<Setter Property="ContentTemplate" Value="{StaticResource ResourceKey=ExecutionView}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<ContentControl Content="{Binding}"
Style="{StaticResource ResourceKey=mainContentControlStyle}" />
</Grid>
</Window>
如果您需要任何更多的代碼,我會很樂意將它張貼。
在此先感謝。
感謝回答......將事件吩咐火....執行和CanExecute方法在ViewModel中? – Ankesh
是的,他們會的。 MVVM Light提供了用於設置的文檔。 – CamronBute
謝謝你的答案:) – Ankesh