ItemsSource의 WPF ItemsControl이 MVVM에서 볼 수있는 컬렉션 모델에 바인딩되어 있습니다. ItemTemplate은 원하는 사용자 정의 컨트롤로 설정됩니다. 그러나 XAML에 지정된 컨트롤 대신 다른 컨트롤을 사용하려는 경우가 있습니다.WPF : ItemsControl에서 두 개의 다른 컨트롤을 어떻게 사용합니까?
어떻게하면 쉽게 할 수 있습니까?
ItemsSource의 WPF ItemsControl이 MVVM에서 볼 수있는 컬렉션 모델에 바인딩되어 있습니다. ItemTemplate은 원하는 사용자 정의 컨트롤로 설정됩니다. 그러나 XAML에 지정된 컨트롤 대신 다른 컨트롤을 사용하려는 경우가 있습니다.WPF : ItemsControl에서 두 개의 다른 컨트롤을 어떻게 사용합니까?
어떻게하면 쉽게 할 수 있습니까?
사용 DataTemplates :
<ItemsControl ItemsSource="{Binding SomeCollectionOfViewModels}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type local:FirstViewModel}">
<Label>Foo</Label>
</DataTemplate>
<DataTemplate DataType="{x:Type local:SecondViewModel}">
<Label>Bar</Label>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
두 개의 서로 다른 유형의 개체가 포함 된 컬렉션이 있고 2 개의 다른 템플릿을 원한다는 것을 알고 있다면. 각 개체 유형에 대해 데이터 템플릿을 만들고 WPF를 그대로 두어 개체 유형을 기반으로 올바른 템플릿을 렌더링 할 수 있습니다. 뷰 뷰 모델을 매핑 할