我正在尝试为我的WPF窗口分配背景。 我在bin\debug\StoredData\wallpaper中有一个.jpg.jpg (我想从那里获得.jpg(。
我开始将这段代码放在.cs文件(新创建的文件(中:
InitializeComponent();
ImageBrush myBrush = new ImageBrush();
myBrush.ImageSource =
new BitmapImage(new Uri("\StoredData\login_wallpaper.jpg", UriKind.Absolute));
this.Background = myBrush;
但是我收到"无效的URI:无法确定URI的格式"消息。 我应该更改什么?
StoredDatalogin_wallpaper.jpg
是一个相对URI。您可以将UriKind
更改为UriKind.Relative
,也可以输入绝对 URI,具体取决于所需的行为。