Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ResourceDictionary.MergedDictionary会导致奇怪的错误_C#_Wpf_Visual Studio 2015_Compiler Errors - Fatal编程技术网

C# ResourceDictionary.MergedDictionary会导致奇怪的错误

C# ResourceDictionary.MergedDictionary会导致奇怪的错误,c#,wpf,visual-studio-2015,compiler-errors,C#,Wpf,Visual Studio 2015,Compiler Errors,在我的WPF应用程序中,我包含了来自另一个项目的ResourceDictionary <Application x:Class="namespace.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Applicat

在我的WPF应用程序中,我包含了来自另一个项目的ResourceDictionary

<Application x:Class="namespace.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!-- This Line causes an Error -->
                <ResourceDictionary Source="pack://application:,,,/Commons;Component/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
注释中的
值不能为空。参数名称:项
。重新启动Visual Studio将返回旧错误

遗憾的是,我还没有发现如何重现此错误,我只能告诉您有关我使用的环境的更多信息:

  • Visual Studio 2015 Professional,版本14.0.25431.01更新3
尽管我怀疑,这些都与我的问题有关,这里是我安装的插件:

  • Resharper Ultimate 2017.1.1
  • GitExtensions版本2.49.03

  • Sinatr的评论暗示我要读更多关于主题的内容

    ThemeInfo
    在自定义控件库中,会自动在
    AssemblyInfo.cs

    [assembly:ThemeInfo(
     ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
                              //(used if a resource is not found in the page, 
                              // or application resource dictionaries)
     ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
                                       //(used if a resource is not found in the page, 
                                       // app, or any theme specific resource dictionaries)
    )]
    
    参数 正如它在自动生成的注释中所述,第一个参数用于确定是否存在主题特定的资源词典或在何处查找主题特定的资源词典。 第二个参数定义是否存在泛型
    资源字典
    generic.xaml

    ResourceDictionaryLocation
    -枚举
    ResourceDictionaryLocation
    -枚举本身用于指定这些字典的位置

    ResourceDictionaryLocation.None
    没有主题词典

    ResourceDictionaryLocation.SourceAssembly
    程序集中存在主题词典,用于定义要设置主题的类型。 要求
    资源字典
    位于
    /Themes
    -文件夹中。稍后解释

    ResourceDictionaryLocation.ExternalAssembly
    主题词典存在于定义主题类型的程序集之外的程序集中

    我不打算解释它是如何工作的

    为什么
    /Themes
    -文件夹 遗憾的是,我找不到太多关于这个的信息。如果有人有更多的信息,请分享

    您是否想过,如何应用无外观控件的样式

    如果一个人创建了一个无外观控件,他会执行以下操作:

    public class MyControl : ControlTemplate
    {
        static MyControl() 
        {
            // This tells WPF to search for a Style for this type
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl)), 
                new FrameworkPropertyMetadata(typeof(MyControl)));
        }
    }
    
    简而言之,WPF中的资源是通过搜索
    逻辑树
    ,然后搜索
    应用程序
    的资源,最后搜索某物来定位的。它们称为
    系统区域
    (这是我从德语翻译的,如果你知道更好的,请告诉我)

    因此,根据
    ThemeInfo
    MyControl
    可能在
    /Themes
    -文件夹的
    /ResourceDictionary
    中有自己的风格,例如
    /Themes/Generic.xaml
    告诉WPF将资源添加到
    系统区域
    ,最终自动解析合适的样式

    /Themes/Generic.xaml中的某个地方:

    <Style TargetType="{x:Type MyControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type MyControl}">
                ..
                </ControlTemplate/>
            </Setter.Value>
        </Setter>
    </Style>
    
    
    ..
    
    这就是为什么上面的
    themeinfo属性
    要求
    Generic.xaml
    位于
    /Themes
    -文件夹中的原因。-不知何故,即使在我的例子中,
    系统区域
    -功能甚至没有用于这个通用文件,这也会导致这些错误。但我没能找到原因

    资料来源:

    • 《Windows演示文稿基金会》DAS UMFASANDED HANDBUCH,莱茵韦克计算版4
    Generic.xaml
    应位于主题文件夹中(阅读答案)。还有两种方法可以指定Uri,请尝试
    Source=“/yoursassembly;component/Themes/Generic.xaml”
    Source=“Themes/Generic.xaml”
    。不要问我为什么,但在某些情况下,这种或那种方式是行不通的。@sinatr我试过你的想法,它奏效了。thx:)