Reputation: 9394
In my App.xaml I have defined a DataTemplate
for my DataType Entry. In this DataTemplate
I'm creating a Grid
with several rows and columns.
The xaml of my DataTemplate
looks like:
<DataTemplate x:Key="EntryTemplate" DataType="entity:Entry" x:Name="EntryTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="hCBase:HControlBase" x:Key="TopRowMargin">
<Setter Property="Margin" Value="2,2,50,2"/>
</Style>
</Grid.Resources>
<hC:HComboBox Grid.Row="0" Grid.Column="0" Header="Entry-Type:" Style="{StaticResource TopRowMargin}" SelectedIndex="0"
ItemsSource="{Binding Source={StaticResource EntryTypesDataProvider}}"
SelectedItem="{Binding EntryType, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
</Grid>
</DataTemplate>
The Template is not finished yet.
Now I want to use this DataTemplate
in a Window, where I have an Entry-Object in the ViewModel. But at the moment I have no glue how to use this.
What do I have to do to display the Entry-Object from my ViewModel in my View using my DataTemplate?
Upvotes: 1
Views: 593
Reputation: 22702
Personally I create ContentControl
, for example in MainWindow with ContentTemplate
like this:
<ContentControl Name="MyContent"
ContentTemplate="{StaticResource EntryTemplate}">
<entity:Entry /> <!-- Your ViewModel here -->
</ContentControl>
Upvotes: 2