私はちょうどそのApplication.Resourcesタグに何かを受け入れることを拒否したのSilverlight 5アプリケーションを持っている: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どちらが私のコントロールに利用できます。たとえば :
実行時にそのバナナを投げますコントロールが、Visual Studioのエディタで 罰金の作品<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}">
(私はテキストは私の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());
とアプリケーションが実行され、その後、スタイルへの参照を削除します。
参考までに、Silverlight Business ApplicationテンプレートからErrorWindow.xaml、Styles.xaml、および両方の.resxを抽出しました。私はちょうどそれがこのアプリで動作しない理由を把握することはできませんでした。