2016-11-12 50 views
0

我的xaml代碼中包含以下資源字典,因此我想縮短路徑,使其不是整個目錄。指定這個文件夾的正確方法是什麼,而不必拼出整個文件結構?在將文件加載到資源字典中時使用的XAML中的WPF路徑

<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}"/> 

..或集那是一個選擇。 這是一個例子它會是什麼樣子,如果在同一個文件夾中的應用程序exe文件有一個文件「1.JPG」:

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

我認爲正確的方法是將它們添加到單獨的文件夾您的解決方案。設置屬性建立行動資源 enter image description here

相關問題