如何从 DataTemplate 派生一个新类,然后用它代替 DataTemplate?
例如,在 C# 中:
public class DerivedDataTemplate : DataTemplate
{
}
然后在 XAML 中:
<local: DerivedDataTemplate DataType="{x:Type local:SomeType}">
<Grid>
... UI here ...
</Grid>
</local:DerivedDataTemplate>
当我尝试使用我的派生数据模板类时,会生成以下异常:
System.Windows.Markup.XamlParseException 未处理 Message="'Grid' 对象无法添加到 'DerivedDataTemplate'。'System.Windows.Controls.Grid' 类型的对象无法转换为 'System.Windows.FrameworkElementFactory' 类型。
有谁知道如何解决此异常并成功使用从 DataTemplate 派生的类?