そのため、従来の MVVM の例では、View Models を Views にマップするために DataTemplate 定義が使用されています。MVVM Light フレームワークでこれを行う標準的な方法は何ですか?マッピングはどこに配置する必要がありますか? 以下は、私が現在行っていることと私が話していることの例です。ブレンド可能性は私にとって重要です!
メイン ウィンドウ:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="STS2Editor.MainWindow"
Title="{Binding ApplicationTitle, Mode=OneWay}"
DataContext="{Binding RootViewModel, Source={StaticResource Locator}}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skins/ApplicationSkin.xaml" />
<ResourceDictionary Source="Resources/ViewMappings.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ContentControl Content="{Binding ApplicationManagementViewModel}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
</Window>
上記のコードでは、私の RootViewModel クラスには、同じプロパティ名を持つクラス ApplicationManagementViewModel のインスタンスがあります。
public ApplicationManagementViewModel ApplicationManagementViewModel {get {...} set {...} }
ResourceDictionary "ViewMappings.xaml" を参照して、ビュー モデルをビューとして表現する方法を指定します。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:STS2Editor.ViewModel">
<DataTemplate DataType="{x:Type local:ApplicationManagementViewModel}">
<local:ApplicationManagementView/>
</DataTemplate>
</ResourceDictionary>
ViewModelLocator を使用してこのようなことを行う必要がありますか? ビューモデルのコレクションはどうですか?