简体   繁体   English

带有ResourceDictionary(WPF)的App.xaml中的“值不能为空”错误

[英]“Value cannot be null” error in App.xaml with ResourceDictionary (WPF)

Using .NET Framework 4.6.1 and I'm using a UI kit that I've installed via NuGet and they are referenced correctly in the project. 使用.NET Framework 4.6.1,我正在使用通过NuGet安装的UI套件 ,并且在项目中正确引用了它们。

App.xaml 应用程式

<Application x:Class="ExampleApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
             xmlns:local="clr-namespace:ExampleApp"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.DarkColorScheme}" />
                <ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.ClassicTheme}" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

MainWindow.xaml MainWindow.xaml

<Window x:Class="ExampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ExampleApp"
        mc:Ignorable="d"
        Title="MainWindow"
        Height="450"
        Width="800">
    <Window.Style>
        <Style TargetType="Window"
               BasedOn="{StaticResource {x:Type Window}}" />
    </Window.Style>
    <Grid>
        <StackPanel Margin="10">
            <Button Content="Click Me"
                    HorizontalAlignment="Center" />
        </StackPanel>
    </Grid>
</Window>

Issues: 问题:

<ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.DarkColorScheme}" />
<ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.ClassicTheme}" />

Both lines in App.xaml are getting the following error: App.xaml中的两行都出现以下错误:

Value cannot be null. Parameter name: item.

I have tried multiple fresh projects, building and rebuilding and I keep getting this error. 我尝试了多个新项目,进行了构建和重建,但我不断收到此错误。 I am able to build the project and I can see the styles from the UI kit correctly applied on MainWindow even though the error is still there. 我能够构建项目,并且即使错误仍然存​​在,也可以从UI套件中正确应用MainWindow的样式中看到样式。

However the styles don't appear on the designer window, I'm not sure if it's related to the error I'm getting or not. 但是样式不会出现在设计器窗口中,我不确定它是否与我收到的错误有关。

Any ideas what could cause this? 有什么想法会导致这种情况吗?

I just tried it and it does the same thing to me... using Visual Studio Enterprise 2017 15.9.7 我只是尝试过,它对我做同样的事情...使用Visual Studio Enterprise 2017 15.9.7

If you look at AdonisUI.ResourceLocator in a decompiler (I used Telerik's JustDecompile), you'll see the definitions: 如果您在反编译器中查看AdonisUI.ResourceLocator(我使用Telerik的JustDecompile),则会看到以下定义:

public static Uri ClassicTheme
{
    get
    {
        return new Uri("pack://application:,,,/AdonisUI.ClassicTheme;component/Resources.xaml", UriKind.Absolute);
    }
}

public static Uri DarkColorScheme
{
    get
    {
        return new Uri("pack://application:,,,/AdonisUI;component/ColorSchemes/Dark.xaml", UriKind.Absolute);
    }
}

public static Uri LightColorScheme
{
    get
    {
        return new Uri("pack://application:,,,/AdonisUI;component/ColorSchemes/Light.xaml", UriKind.Absolute);
    }
}

If you change your App.xaml to reference using these values then it works. 如果您将App.xaml更改为使用这些值进行引用,则它将起作用。

<ResourceDictionary Source="pack://application:,,,/AdonisUI.ClassicTheme;component/Resources.xaml" />
<ResourceDictionary Source="pack://application:,,,/AdonisUI;component/ColorSchemes/Dark.xaml" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM