【问题标题】:Cannot locate resource 'themes/style/master.xaml'找不到资源“主题/样式/master.xaml”
【发布时间】:2014-07-02 09:02:31
【问题描述】:

这是我的解决方案资源管理器:

我想做这个:

ResourceDictionary dictionary = new ResourceDictionary();
dictionary.Source = new Uri("../Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary());

在PageWithoutMaster的构造函数中。

我得到错误:找不到资源'themes/style/master.xaml'

我做错了什么?为什么要在路径中添加style文件夹?

【问题讨论】:

  • 您是否尝试过使用绝对 URI:pack://application:,,,/projectname;component/Themes/Generic.xaml
  • dictionary.Source= new Uri("Themes/Generic.xaml", UriKind.Relative);
  • @HeenaPatil 同样的错误。
  • @dkozi 它不起作用:(
  • 我猜你将 master.xaml 合并到 Generic.xaml 中。您是否尝试以与 /assemblyname;component/Style/master.xaml 相同的方式将路径设置为 master.xaml,在其中引用它?

标签: wpf path


【解决方案1】:

作为dkozl pointed out,您可以通过使用Pack URI 并在路径中包含程序集名称来解决此问题

假设您的资源文件如下所示:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:WpfApp4.Themes">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Style/Master.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

从项目属性中获取程序集名称:

然后改为更新到这个值:

<ResourceDictionary Source="WpfApp4;component/Style/Master.xaml" />

【讨论】:

    猜你喜欢
    • 2020-06-28
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 2015-04-11
    相关资源
    最近更新 更多