[英]WPF: ImageSource relative to executable location not project location
[英]WPF Images Relative Location
我有WPF項目,在項目里面我有一個文件夾調用Images
,它包含一些png和gif文件。 其中的所有文件都是Build Action= Resources
和Copy to Output Directory = Do not copy
。
我使用以下代碼將其綁定到Image:
ImageSource ImageStatus = new BitmapImage(new Uri("/MPAL;component/Images/usbreader0001.png", UriKind.Relative));
MPAL
是我的項目名稱和默認程序集。
我有一個問題,圖像編譯到哪里? 因為我能夠運行它而不會出現問題。
我稱之為正確的方法嗎?
謝謝。
Build Action = Resources將圖像放在名為projectname .g.resources的文件中。 編譯時,該資源文件鏈接到您的exe。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.