我已經DOEN是基於這篇文章: http://msdn.microsoft.com/en-us/library/aa348547.aspx的Silverlight:App.Current.Resources是空
我試圖讓從在App.xaml中加載的合併字典的字符串。 我想從一個不是代碼背後的代碼中做到這一點。 我知道原則上可以加載資源文件,因爲頁面元素是通過Styles.xaml文件中包含的樣式的xaml標記進行樣式設置的。
App.xaml文件
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="theApp.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
的styles.xaml文件(編輯了下來爲簡單起見)
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:clr="clr-namespace:System;assembly=mscorlib">
<clr:String x:Key="applicationName">TheKraken</clr:String>
</ResourceDictionary>
的代碼行我使用嘗試和訪問資源
string appName = (string)App.Current.Resources["applicationName"];
任何想法我失蹤?
在應用程序啓動過程中,您是否嘗試訪問資源?您的實際使用看起來正確。 – 2010-09-30 09:50:49
我試圖在頁面顯示後使用它。它是自定義登錄和令牌緩存控制的一部分。我其實已經想出了這個問題。 – 2010-09-30 15:07:27