2012-05-18 34 views
2

所以我有一個圖書館,託管我的所有圖像。這適用於我的WinForms控件;但是,我很難在WPF中使用這個類庫的資源。如何在WPF控件內的類庫中使用.resx文件?

MyApp.Resources //Is my control library project. 
Resources //Is the folder that contains all my images at the root of the project. 

如何從我的類庫中引用WPF控件中的圖像?

我曾嘗試:

<ImageBrush ImageSource="/MyApp.Resources;Resources/manage.png" /> 

--UserControl物業

Resources="pack://application:,,,/MyApp.Resources;Resources.resx"> 
+0

退房此鏈接http://www.codeproject.com/Articles/35159/WPF-Localization-Using-RESX-Files – Phil

回答

1
  1. 添加一個新的RESX文件。
  2. 在這個文件中添加你的文件。
  3. 在VS的Solution Explorer中檢查您的RESX文件,並將構建操作從Embedded Resource更改爲Resource。
  4. 打開RESX文件並將訪問修飾符從Internal更改爲Public。
  5. 創建新的資源字典文件(例如Files.xaml):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <BitmapImage x:Key="someImage" 
       UriSource="/YourAppNamespace;component/Resources/image.png" /> 
</ResourceDictionary> 
  • 導入字典中的窗口或應用資源:
  • <ResourceDictionary> 
        <ResourceDictionary.MergedDictionaries> 
         <ResourceDictionary Source="Files.xaml" /> 
        </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
    
  • 在使用WPF應用程序烏爾形象:
  • <Image Source="{StaticResource someImage}" /> 
    
    +0

    好的,謝謝我要檢查出來。 – meanbunny