【问题标题】:Merged Resource Dictionary folder of images in DLL not found未找到 DLL 中图像的合并资源字典文件夹
【发布时间】:2019-07-31 19:14:33
【问题描述】:

此处是 WPF 进程的新手,并尝试定义在实用程序 DLL 中维护的合并字典集合的合并字典。我正在尝试解决资源位置错误。

错误

  • IOException:找不到资源“ui/wpf/imagelist16x16.xaml”

Theme.xaml

<ResourceDictionary       
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/UI/WPF/ImageList16x16.xaml"  />
        <!--Future xaml file references-->
    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="EmptyStyle"/>
</ResourceDictionary>

ImageList16x16.xaml

<ResourceDictionary         
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:clr="clr-namespace:System;assembly=mscorlib">

    <BitmapImage x:Key="Accept" UriSource="UI/Resources/Images16x16/accept.png"/>
</ResourceDictionary>

用户控制资源参考

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/BHP_Utilities;component/UI/WPF/Theme.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

执行时,会根据其中的字典引用找到 Theme.xaml,因为发生错误。两个 xaml 文件的 构建选项Page 并且 Custom Tool 属性设置为 XamlIntelliSenseFileGenerator

【问题讨论】:

    标签: c# wpf xaml resourcedictionary


    【解决方案1】:

    由于文件在同一个文件夹中,您可以尝试删除“/UI/WPF/”

    <ResourceDictionary Source="ImageList16x16.xaml"  />
    

    【讨论】:

    • 这是一个学习绝对路径与相对路径声明的时刻。 ImageList16x16.xaml 被列为带有前导“/”的绝对路径。由于 Theme.xaml 位于“UI/WPF”中,因此试图定位的路径是不存在的“UI/WPF/UI/WPF”。通过删除前导“/”,路径声明变为相对路径,用于定位图像列表 xaml 文件。由于相对路径定义,最终必须删除所有“/UI/WPF”才能找到图像。此外,必须将图像文件夹重新定位到 WPF 文件夹结构中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多