2014-01-16 91 views
0

假設我有3個項目:LibClassProj,Proj1Proj2在windows phone develompment by c#中。 Proj1Proj2分享LibClassProj中的代碼。它工作正常。現在的問題是,我無法從Proj1Proj2的xaml獲取LibClassProj的AppResources.resx中的字符串。WP8多個項目由Windows Phone類庫共享代碼,但無法共享AppResources.resx

例如,這是來自LibClassProj的xaml的一部分。

SelectableButtonText="{ 
        Binding Path=LocalizedResources.strTestButtonTitleClose, 
        Source={StaticResource LocalizedStrings}}" 

當我把strTestButtonTitleClose在LibClassProj的AppResources.resx文件,我不能讓這個字符串Proj1Proj2(這意味着在設置Proj1Proj2啓動項目)。如果我把它放在Proj1的AppResources.resx中,當我選擇Proj1作爲啓動項目時,我可以得到它。與Proj2相同。

任何人都知道如何才能將字符串只在LibClassProj的AppResources.resx,我可以從其他項目訪問它?謝謝。

回答

2

你需要從每個項目的App.xaml中引用共享資源:

<Application 
    ... 
    xmlns:lib="clr-namespace:YourApp.LibClassProj;assembly=YourApp.LibClassProj"> 

    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       ... 
      </ResourceDictionary.MergedDictionaries> 

      <lib:LocalizedStrings x:Key="LocalizedStrings"/> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 

那麼你應該能夠使用字符串像你在這兩個Proj1和Proj2提到:

<TextBlock Text="{Binding Source={StaticResource LocalizedStrings}, Path=LocalizedResources.strTestButtonTitleClose}"/> 
+0

謝謝你的迴應。我努力了這一點,它找不到LocalizedStrings。 YourApp Here:'xmlns:lib =「clr-namespace:YourApp.LibClassProj; assembly = YourApp.LibClassProj」'你的意思是Proj1.LibClassProj? – Vigor

+0

「Proj1.LibClassProj」是否存在?我的理解是你有「LibClassProj」,「Proj1」和「Proj2」。我的建議是在每個Proj1和Proj2中定義xmlns:lib,並指向LibClassProj。這允許在Proj1和Proj2中使用來自LibClassProj的字符串。 – siger

+0

嗨@mleroy,我明白你的意思。我只是對我的情況** YourApp **應該是什麼感到困惑,我只有VS中的3個項目:'LibClassProj','Proj1'和'Proj2'。 'LibClassProj'已被添加到'Proj1'和'Proj2'的參考。 – Vigor