C# 发布应用程序时未找到资源字典
我已经编写了一个WPF/C应用程序,我正试图发布它。应用程序当前使用两个资源字典在主题之间切换。下面是App.xaml文件,它指定了两个资源字典:C# 发布应用程序时未找到资源字典,c#,wpf,xaml,visual-studio-2013,resourcedictionary,C#,Wpf,Xaml,Visual Studio 2013,Resourcedictionary,我已经编写了一个WPF/C应用程序,我正试图发布它。应用程序当前使用两个资源字典在主题之间切换。下面是App.xaml文件,它指定了两个资源字典: <Application x:Class="TopDeck.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<Application x:Class="TopDeck.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:visualizationToolkit="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush Color="#d0157820" x:Key="muddyBrush"/>
<Style TargetType="TextBlock" x:Key="MenuFont">
<Setter Property="Foreground" Value="Black"/>
</Style>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="DarkTheme.xaml"/>
<ResourceDictionary Source="LightTheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
问题是,当我发布此应用程序并尝试运行它时,会收到以下错误消息:
{"Could not find file 'C:\\Users\\Emerald\\AppData\\Local\\Apps\\2.0\\JTHXX0YW.KTK\\1MZ2M8ZP.TV0\\topd..tion_1428230028859fe5_0001.0000_ec5ac614e9be24b1\\DarkTheme.xaml'.":"C:\\Users\\Emerald\\AppData\\Local\\Apps\\2.0\\JTHXX0YW.KTK\\1MZ2M8ZP.TV0\\topd..tion_1428230028859fe5_0001.0000_ec5ac614e9be24b1\\DarkTheme.xaml"}
有人知道我可以做些什么来维护应用程序中的资源字典切换,但要避免这个错误吗?是否有办法指定我希望DarkTheme.xaml和LightTheme.xaml存在于已发布的应用程序中?如果没有,是否有一种方法可以在不显式加载文件的情况下引用这些资源字典?我猜发布是指通过ClickOnce发布。因此,要包含您的DarkTheme.xaml和LightTheme.xaml,请转到它们的属性并将构建操作设置为“内容”。然后您可以检查(在项目属性>发布>应用程序文件中)它们是否确实包含在内。但是,也要考虑以下方式来实现你的目标:
var themeDict = new ResourceDictionary();
var uriPath = string.Format("/{0};component/DarkTheme.xaml",
Assembly.GetEntryAssembly().GetName().Name);
var uri = new Uri(uriPath, UriKind.RelativeOrAbsolute);
themeDict.Source = uri;
Application.Current.Resources.MergedDictionaries.Add(themeDict);
这里要做的是构造(已经存在的)DarkTheme.xaml文件的url,然后告诉ResourceDictionary该url。这样,您就不需要将构建操作更改为内容,也不需要部署任何内容。我想发布是指通过ClickOnce发布。因此,要包含您的DarkTheme.xaml和LightTheme.xaml,请转到它们的属性并将构建操作设置为“内容”。然后您可以检查(在项目属性>发布>应用程序文件中)它们是否确实包含在内。但是,也要考虑以下方式来实现你的目标:
var themeDict = new ResourceDictionary();
var uriPath = string.Format("/{0};component/DarkTheme.xaml",
Assembly.GetEntryAssembly().GetName().Name);
var uri = new Uri(uriPath, UriKind.RelativeOrAbsolute);
themeDict.Source = uri;
Application.Current.Resources.MergedDictionaries.Add(themeDict);
这里要做的是构造(已经存在的)DarkTheme.xaml文件的url,然后告诉ResourceDictionary该url。这样,您就不需要将构建操作更改为内容,也不需要部署任何内容。谢谢!我用了你的代码,它成功了。对于其他访问此页面的人,我使用ClickOnce发布。谢谢!我用了你的代码,它成功了。对于访问此页面的其他人,我使用ClickOnce发布。