2016-11-12 10 views
0

xamlコードに次のリソースディクショナリがあります。そのディレクトリ全体ではなくパスを短縮したいと思います。ファイル構造全体を記述することなくこのフォルダを指定する正しい方法は何ですか?C#WPFリソースディクショナリにファイルをロードするときに使用するXAMLのパス

<UserControl.Resources> 
    <ResourceDictionary> 
     <BitmapImage x:Key="1" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/1.jpg"/> 
     <BitmapImage x:Key="2" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/2.jpg"/> 
     <BitmapImage x:Key="3" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/3.jpg"/> 
     <BitmapImage x:Key="4" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/4.jpg"/> 
    </ResourceDictionary> 
</UserControl.Resources> 

答えて

1

あなたはBitmapImage

<BitmapImage x:Key="1" BaseUri="{x:Static local:GlobalPaths.BasePath}" UriSource="1.jpg"/> 


public class GlobalPaths 
{ 
    public static readonly Uri BasePath = new Uri(@"C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/"); 
} 

BaseUriプロパティを使用するか、このような各ファイルのパスを設定できますアセンブリ場合siteoforiginを使用する

<BitmapImage x:Key="1" UriSource="{x:Static local:GlobalPaths.File1}"/> 

..Orセットの相対パスそれはオプションです。 これは、ファイル「1.JPGは、」アプリケーションのexeファイルと同じフォルダにあった場合、それは次のようになります方法の例です:

<BitmapImage x:Key="1" UriSource="pack://siteoforigin:,,,/1.jpg"/> 
0

私は適切な方法は、別のフォルダにあなたのソリューションに追加することだと思います。プロパティビルドアクションで設定リソース enter image description here

関連する問題