协议:pack://
一种用于访问编译时已经知道的文件,用application:///
一种用于访问编译时不知道、运行时才知道的文件,用siteoforigin:///
一般用逗号代替斜杠,也就是改写作application:,,,
用XAML引用资源
<Window.Resources> <BitmapImage x:Key="img_black" UriSource="img/black-48.png" DecodePixelWidth="48" /> <BitmapImage x:Key="img_green" UriSource="img/green-48.png" DecodePixelWidth="48" /> <BitmapImage x:Key="img_red" UriSource="img/red-48.png" DecodePixelWidth="24" /> <BitmapImage x:Key="img_black24" UriSource="img/black-48.png" DecodePixelWidth="24" /> </Window.Resources>
<Grid.Background> <ImageBrush ImageSource="pack://application:,,,/watermark.png" /> </Grid.Background>
|
用代码引用资源
Image img; img.Source=new BitmapImage(new Uri("pack://application:,,,/images/my.jpg"),UriKind.Relative);
|