WPF window 背景图片中的 URI 路径
URI path in WPF window background image
我正在尝试为我的 WPF window 分配背景。
我在 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;
但是我收到 "Invalid URI: The format of the URI could not be determined" 消息。
我应该改变什么?
\StoredData\login_wallpaper.jpg
是一个相对 URI。您可以将 UriKind
更改为 UriKind.Relative
,或输入绝对 URI,具体取决于您想要的行为。
我正在尝试为我的 WPF window 分配背景。 我在 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;
但是我收到 "Invalid URI: The format of the URI could not be determined" 消息。 我应该改变什么?
\StoredData\login_wallpaper.jpg
是一个相对 URI。您可以将 UriKind
更改为 UriKind.Relative
,或输入绝对 URI,具体取决于您想要的行为。