我有一个Silverlight 5应用程序,只是拒绝在其Application.Resources标签接受任何东西:如何在Silverlight 5中添加应用程序范围的资源字典?
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="My.Awesome.App"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles.xaml"/>
<ResourceDictionary>
<App:ApplicationResources x:Key="ApplicationResources" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
无论是Styles.xaml还是ApplicationResources是提供给我的控制。 例如:
<controls:ChildWindow
x:Class="My.Awesome.ErrorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Title="{Binding Path=Errors.ErrorWindowTitle, Source={StaticResource ApplicationResources}}"
Style="{StaticResource ErrorWindowStyle}">
控制在运行时将其扔香蕉,但在Visual Studio编辑器的工作原理罚款(我可以看到文本从我ApplicationResources推出)。 的应用程序:从所述的App.xaml ApplicationResources是如下:
namespace My.Awesome
{
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Browser;
/// <summary>
/// Wraps access to the strongly-typed resource classes so that you can bind control properties to resource strings in XAML.
/// </summary>
public sealed class ApplicationResources
{
private static readonly ApplicationStrings applicationStrings = new ApplicationStrings();
private static readonly ErrorResources errorResources = new ErrorResources();
/// <summary>
/// Gets the <see cref="ApplicationStrings"/>.
/// </summary>
public ApplicationStrings Strings
{
get { return applicationStrings; }
}
/// <summary>
/// Gets the <see cref="ErrorResources"/>.
/// </summary>
public ErrorResources Errors
{
get { return errorResources; }
}
}
}
和我有与指定的(My.Awesome)正确的命名空间和与所述处理器PublicResXFileCodeGenerator对应ApplicationStrings.resx和ErrorResources.resx。
我把范围缩小到Application.Resources词典不工作,因为如果我这样做在后面的代码:
this.Resources.Add("ApplicationResources", new ApplicationResources());
和删除提及样式,然后在应用程序运行。
对于参考值I萃取ErrorWindow.xaml,Styles.xaml和从Silverlight业务应用程序模板二者的.resx;它工作得很好,我只是不明白为什么它不适用于这个应用程序。