Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用App.xaml中的数据模板_C#_Wpf_Datatemplate - Fatal编程技术网

C# 使用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>

在我的App.xaml中,我为我的数据类型条目定义了一个
DataTemplate
。在这个
DataTemplate
中,我正在创建一个包含多行和多列的
网格

my
DataTemplate
的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>