导致这种报错的原因一般是XAML中的样式资源顺序错误,即使先使用了声明的resource资源。
错误示例:
key为ComboBoxStyle的样式中引用了key为EditableBule的样式,ComboBoxStyle的顺序是在最上面的,这样就会导致引发这个异常。
<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
<Setter Property="Template" Value="{StaticResource EditableBule}"/>
</Style>
<ControlTemplate x:Key="EditableBule" TargetType="{x:Type ComboBox}"></ControlTemplate>
正确示例:
<ControlTemplate x:Key="EditableBule" TargetType="{x:Type ComboBox}"></ControlTemplate>
<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
<Setter Property="Template" Value="{StaticResource EditableBule}"/>
</Style>