Could I load a 开发者_Go百科image from xaml file? for example: having a folder IMAGES that contains all of images resources. These images were not added to project. I want to load an image from xaml file as following code:
<Image Source="/IMAGES/gift.png" Height="70" Width="70" VerticalAlignment="Top" />
Is it possible or do I have to load this from behind code?
You can use Pack URIs with siteoforigin authority like this:
<Image Source="pack://siteoforigin:,,,/IMAGES/gift.png"
Height="70" Width="70" VerticalAlignment="Top" />
if you have a folder of images in your project folder then try this:
static string path = System.AppDomain.CurrentDomain.BaseDirectory;
static string debug = Path.GetDirectoryName(path);
static string bin = Path.GetDirectoryName(debug);
static string DefaultLayoutFilePath = Path.GetDirectoryName(bin);
public string xmlDefaultLayoutFile = DefaultLayoutFilePath + "\\IMAGES\\gift.png";
and add for all images properties change them to copy always to output folder. it will surely work.
精彩评论