C# 使用App.xaml中的数据模板
在我的App.xaml中,我为我的数据类型条目定义了一个C# 使用App.xaml中的数据模板,c#,wpf,datatemplate,C#,Wpf,Datatemplate,在我的App.xaml中,我为我的数据类型条目定义了一个DataTemplate。在这个DataTemplate中,我正在创建一个包含多行和多列的网格 myDataTemplate的xaml如下所示: <DataTemplate x:Key="EntryTemplate" DataType="entity:Entry" x:Name="EntryTemplate"> <Grid> <Grid.RowDefinitions>
DataTemplate
。在这个DataTemplate
中,我正在创建一个包含多行和多列的网格
myDataTemplate
的xaml如下所示:
<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>
模板尚未完成
现在我想在一个窗口中使用这个DataTemplate
,在这个窗口中,我在ViewModel中有一个Entry对象。但是现在我没有胶水怎么用
要使用我的DataTemplate在我的视图中显示ViewModel中的条目对象,我必须做些什么?我个人创建了ContentControl
,例如在带有ContentTemplate
的主窗口中,如下所示:
<ContentControl Name="MyContent"
ContentTemplate="{StaticResource EntryTemplate}">
<entity:Entry /> <!-- Your ViewModel here -->
</ContentControl>