这是什么意思:"the ContentControl does not use the DataTemplate automatically."?

What does it mean: "the ContentControl does not use the DataTemplate automatically."?

我正在努力让我的数据模板绑定工作;我明确地将我的 DataTemplate 绑定到数据类型

<DataTemplate DataType="{x:Type local:ExcelReportVM}">
    <local:ExcelReport DoubleClickHandler="{Binding}">
        <local:ExcelReport.RowColorConverter>
            <local:ReportRowColorConverter/>
        </local:ExcelReport.RowColorConverter>
    </local:ExcelReport>
</DataTemplate>

但是,我发现即使我的control.DataContextExcelReportVM,上面的DataTemplate根本就不适用。

然后我read in MSDN那个

if you are binding a ContentControl to a collection of Task objects, the ContentControl does not use the DataTemplate automatically. This is because the binding on a ContentControl needs more information to distinguish whether you want to bind to an entire collection or the individual objects. If your ContentControl is tracking the selection of an ItemsControl type, you can set the Path property of the ContentControl binding to "/" to indicate that you are interested in the current item. For an example, see How to: Bind to a Collection and Display Information Based on Selection. Otherwise, you need to specify the DataTemplate explicitly by setting the ContentTemplate property.

这个解释听起来很抽象,看了几遍都不知道在说什么。有人愿意用适当的例子来解释吗?

如果您将 ContentControlContent 属性 设置或绑定到 ExcelReportVM 对象的实例,则应用隐式 DataTemplate

<ContentControl x:Name="control" />

content.Content = new ExcelReportVM();