我有这个自定义控件和我自己的逻辑
public class BackButton : Button
{
public BackButton()
{
this.DefaultStyleKey = typeof(Button);
this.Click += (s, e) => {
Services.NavigationService.GoBack();
};
}
}
我想将默认样式 BackButtonStyle 应用于它。我不想编辑 StandardStyles.xaml 所以它在另一个 ResourceDictionary
<Style TargetType="controls:BackButton" BasedOn="{StaticResource BackButtonStyle}"/>
在 App.xaml 中引用
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
<ResourceDictionary Source="Common/FrameworkStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
它正在构建,但抛出了这个异常:
Message = "Cannot find a Resource with the Name/Key BackButtonStyle [Line: 15 Position: 44]"
我究竟做错了什么 ?