포함 된 ContentControl
에 특정 뷰를 "삽입"하는 일반 뷰가 있습니다 (이 도움말에서 생성 된 기능 ->help 1 - help 2).ViewModel에 뷰의 일반 개체 알리기
내 플레이의 기본 소스는 다음과 같습니다
MyGenericView.xaml
<UserControl x:Class="MyNS.MyGenericView"
... >
<UserControl.Resources>
<vml:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</UserControl.Resources>
<Grid DataContext="{Binding MyGenericViewModel, Source={StaticResource Locator}}">
<ContentControl Content="{Binding MyObject}" />
</Grid>
</UserControl>
CustomerView.xaml
<UserControl x:Class="AnotherNS.CustomerView"
... >
<Grid>
<StackPanel Orientation="Vertical">
<Label Content="Description" />
<TextBox Text="{Binding description}" />
</StackPanel>
</Grid>
</UserControl>
Crud.xaml
: 나는에 사용하는 리소스 사전에 정확한보기 무엇을 "해결" 표시, DataType
의 MyObject
개체에 따라 일반보기에서 제공됩니다.
<ResourceDictionary ... >
<DataTemplate DataType="{x:Type mo:Customer}">
<vw:CustomerView />
</DataTemplate>
<DataTemplate DataType="{x:Type mo:Product}">
<vw:ProductView />
</DataTemplate>
...
</ResourceDictionary>
괜찮습니다. 나는 특정보기 (고객, 제품 등)를 통해 MyObject
을 관리 할 수 있습니다.
음. 그게 내 문제 야.
모든 특정보기에는 고유 한 ViewModels이 있으며 물론 각보기의 데이터를 관리합니다. 하지만 일반 뷰는 viewmodel이 아닌 특정 뷰에 제공하기 때문에 (뷰 모델에서) 내가 작업하고있는 객체 (MyObject)가 무엇인지 알지 못합니다.
특정보기의 ViewModels에서보기를 "명령하는"개체를 알 수있는 방법이 있습니까?
. 어떤 인스턴스가 올바른 객체인지에 대해 다른 인스턴스가 혼동하지 않을까요? 응답을 업데이트 할 수 있습니까? 고마워. –
음. 내 프로젝트에서 이미 MVVMLight를 사용하고 있습니다. 내가 제공하는 "메신저 개체"를 사용하려고합니다. 감사. –