在设计时找不到 C# 资源
C# resource not found at design time
几天后,我在打开任何 xaml 文件时收到 "Resource not found" 消息,但是编译和执行应用程序没有问题。我正在为我的 UI 设计使用 MahApps.Metro 并且已经尝试清理和重建整个解决方案以及 "reinstalled" MahApps.Metro(版本 1.4.3)包使用 Visual Studio 混合 2015.
我的App.xaml看起来像这样:(定义了更多的样式,但是WindowStyle显示"Resource could not be resolved"错误)
<Application x:Class="Edge_Player.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Edge_Player"
xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:system="clr-namespace:System;assembly=mscorlib"
StartupUri="Player.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Theme/Dark.xaml"/>
<ResourceDictionary Source="Localization/StringResources.xaml"/>
<ResourceDictionary Source="Resources/Icons/Icons.xaml"/>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatSlider.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="Theme/Base/Dark.xaml"/>
<ResourceDictionary Source="Theme/Accents/Orange.xaml"/>
<ResourceDictionary Source="Controls/Slider.xaml"/>
<ResourceDictionary Source="Controls/Menu.xaml"/>
</ResourceDictionary.MergedDictionaries>
<system:Double x:Key="WindowTitleFontSize">14</system:Double>
<BitmapImage x:Key="DesignCover" UriSource="Resources/emptyCover.png"/>
<BitmapImage x:Key="DesignImage" UriSource="Resources/osu_mp_wallpaper.jpg"/>
<Style x:Key="WindowStyle"
TargetType="{x:Type metro:MetroWindow}"
BasedOn="{StaticResource {x:Type metro:MetroWindow}}">
<Setter Property="Background" Value="{DynamicResource Primary}"/>
<Setter Property="Foreground" Value="{DynamicResource Accent}"/>
<Setter Property="BorderBrush" Value="{DynamicResource Border}"/>
<Setter Property="GlowBrush" Value="{DynamicResource Border}"/>
<Setter Property="NonActiveBorderBrush" Value="{DynamicResource Warn}"/>
<Setter Property="NonActiveGlowBrush" Value="{DynamicResource Warn}"/>
<Setter Property="NonActiveWindowTitleBrush" Value="{DynamicResource PrimaryDark}"/>
<Setter Property="WindowTitleBrush" Value="{DynamicResource PrimaryDark}"/>
<Setter Property="ShowIconOnTitleBar" Value="False"/>
</Style>
"WindowStyle" 中使用的所有动态资源都在单独的文件中定义。
我刚刚找到导致此行为发生的原因:在 XAML 编辑器中,项目代码不知何故被停用了...(我现在觉得自己很愚蠢)
我遇到了类似的问题,但是,我的项目处于活动状态并且在不同的解决方案中。问题是向现有项目添加新资源。先前存在的资源在设计和 运行 时间内有效,但新资源文件仅在 运行 时间内有效。
解决方法很简单。我删除了 .sou 文件或 .vs 文件夹(取决于版本),我的所有资源都在设计时工作。
.sou 或 .vs 出错时是当今世界万恶之源。删除它们可以解决很多问题。我应该先试试这个。
几个小时后我发现问题是平台目标设置为 x64。
将其更改为 AnyCPU 后,设计中的资源有效..
几天后,我在打开任何 xaml 文件时收到 "Resource not found" 消息,但是编译和执行应用程序没有问题。我正在为我的 UI 设计使用 MahApps.Metro 并且已经尝试清理和重建整个解决方案以及 "reinstalled" MahApps.Metro(版本 1.4.3)包使用 Visual Studio 混合 2015.
我的App.xaml看起来像这样:(定义了更多的样式,但是WindowStyle显示"Resource could not be resolved"错误)
<Application x:Class="Edge_Player.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Edge_Player"
xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:system="clr-namespace:System;assembly=mscorlib"
StartupUri="Player.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Theme/Dark.xaml"/>
<ResourceDictionary Source="Localization/StringResources.xaml"/>
<ResourceDictionary Source="Resources/Icons/Icons.xaml"/>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatSlider.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="Theme/Base/Dark.xaml"/>
<ResourceDictionary Source="Theme/Accents/Orange.xaml"/>
<ResourceDictionary Source="Controls/Slider.xaml"/>
<ResourceDictionary Source="Controls/Menu.xaml"/>
</ResourceDictionary.MergedDictionaries>
<system:Double x:Key="WindowTitleFontSize">14</system:Double>
<BitmapImage x:Key="DesignCover" UriSource="Resources/emptyCover.png"/>
<BitmapImage x:Key="DesignImage" UriSource="Resources/osu_mp_wallpaper.jpg"/>
<Style x:Key="WindowStyle"
TargetType="{x:Type metro:MetroWindow}"
BasedOn="{StaticResource {x:Type metro:MetroWindow}}">
<Setter Property="Background" Value="{DynamicResource Primary}"/>
<Setter Property="Foreground" Value="{DynamicResource Accent}"/>
<Setter Property="BorderBrush" Value="{DynamicResource Border}"/>
<Setter Property="GlowBrush" Value="{DynamicResource Border}"/>
<Setter Property="NonActiveBorderBrush" Value="{DynamicResource Warn}"/>
<Setter Property="NonActiveGlowBrush" Value="{DynamicResource Warn}"/>
<Setter Property="NonActiveWindowTitleBrush" Value="{DynamicResource PrimaryDark}"/>
<Setter Property="WindowTitleBrush" Value="{DynamicResource PrimaryDark}"/>
<Setter Property="ShowIconOnTitleBar" Value="False"/>
</Style>
"WindowStyle" 中使用的所有动态资源都在单独的文件中定义。
我刚刚找到导致此行为发生的原因:在 XAML 编辑器中,项目代码不知何故被停用了...(我现在觉得自己很愚蠢)
我遇到了类似的问题,但是,我的项目处于活动状态并且在不同的解决方案中。问题是向现有项目添加新资源。先前存在的资源在设计和 运行 时间内有效,但新资源文件仅在 运行 时间内有效。
解决方法很简单。我删除了 .sou 文件或 .vs 文件夹(取决于版本),我的所有资源都在设计时工作。
.sou 或 .vs 出错时是当今世界万恶之源。删除它们可以解决很多问题。我应该先试试这个。
几个小时后我发现问题是平台目标设置为 x64。
将其更改为 AnyCPU 后,设计中的资源有效..