我正在尝试将图像作为UserControl的背景添加。根据变量的值,我需要更改该背景,但无论我使用什么路径或Uri格式,背景都不会更改。
我在stackoverflow上看到了很多问题,但没有一个可以解决我的问题。 我放下了下面的代码:
if (callback.liveUvis.ContainsUVI(uvi))
{
this.Status.Text = "LIVE";
ImageBrush imgB = new ImageBrush();
BitmapImage btpImg = new BitmapImage();
btpImg.UriSource = new Uri(@"///IMG///Live///bck_frame_info_video_live.png", UriKind.Relative);
//imgB.ImageSource = new BitmapImage(new Uri("~/IMG/Live/bck_frame_info_video_live.png", UriKind.RelativeOrAbsolute));
//imgB.ImageSource = new BitmapImage(new Uri("ms-appx:///IMG/Live/bck_frame_info_video_live.png"));
imgB.ImageSource = btpImg;
this.Background = imgB;
}
当我尝试附加图片时,我也遇到了同样的问题...我猜这也与Uri格式有关,但为了保险起见,我还是把代码留在这里 :)
private void setIcon_Desc(string dd)
{
try
{
Image img = new Image();
img.Source = new BitmapImage(new Uri(this.BaseUri, "IMG/pictos_small/white/160dpi/" + dd + ".png"));
img.Stretch = Stretch.None;
this.Icon = img;
this.Sport.Text = callback.disc.getDescription(dd).ToUpper();
}
catch(Exception ex)
{
callback.exception.writeExceptions(ex);
}
}
谢谢您的提前帮助!
<Image Source="IMG/Live/bck_frame_info_video_live.png" />
的东西打开文件(也就是说,如果您的图片在“IMG”文件夹的“Live”子文件夹中)。使用Uri对象时可能会有一些微妙之处,因此我建议首先尝试使用我提供的代码直接从XAML中进行。 - Kevin Gossems-appx
方案,但只有一个/。 - Kevin Gosse