【问题标题】:Reference to a basic style from another ResourceDictionary not found未找到从另一个 ResourceDictionary 引用基本样式
【发布时间】:2013-09-13 15:12:47
【问题描述】:

我有这个带有我自己逻辑的自定义控件

     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]"

我做错了什么?

【问题讨论】:

    标签: c# xaml windows-8 windows-store-apps winrt-xaml


    【解决方案1】:

    BackButtonStyle 的目标类型为Button,因此您不能将BackButtonStyle 用作controls:BackButton. 目标类型的基本样式

    <Style x:Key="BackButtonStyle" TargetType="Button">
    

    【讨论】:

      猜你喜欢
      • 2021-03-30
      • 2015-10-21
      • 1970-01-01
      • 2016-04-25
      • 2017-04-15
      • 2014-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多