C# 自定义ContentControl在模板化后不显示内容?

C# 自定义ContentControl在模板化后不显示内容?,c#,.net,wpf,templates,xaml,C#,.net,Wpf,Templates,Xaml,我创建了一个名为DataGridInsertRowPresenter的新自定义控件,该控件继承自ContentControl。一切都很顺利 然后我添加了一个新样式,它改变了它的模板,不再显示内容。以下是控件: public class DataGridInsertRowPresenter : ContentControl { static DataGridInsertRowPresenter() { DefaultStyleKeyProperty.OverrideMeta

我创建了一个名为
DataGridInsertRowPresenter
的新自定义控件,该控件继承自
ContentControl
。一切都很顺利

然后我添加了一个新样式,它改变了它的模板,不再显示内容。以下是控件:

public class DataGridInsertRowPresenter : ContentControl {
    static DataGridInsertRowPresenter() {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(DataGridInsertRowPresenter), new FrameworkPropertyMetadata(typeof(DataGridInsertRowPresenter)));
    }
}
这是我的模板:

<Style TargetType="{x:Type Primitives:DataGridInsertRowPresenter}" BasedOn="{StaticResource {x:Type ContentControl}}" >
    <Setter Property="Template" >
        <Setter.Value>
            <ControlTemplate>
                <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


我的代码有什么问题?

可能是您的assemblyinfo.cs缺少一个属性,该属性告诉它在哪里查找资源。检查assemblyinfo.cs中是否有以下代码:

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page, 
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries)
)]


并确保您的样式位于Themes\Generic.xaml(或作为合并词典引用)

您需要将
TargetType
添加到
ControlTemplate
中,因为
Control
没有名为
Content
的属性:

<ControlTemplate TargetType="{x:Type Primitives:DataGridInsertRowPresenter}">

您找到解决方案了吗?任何一个建议的答案,在这种情况下,你能把它标记为已回答吗?