小编Eva*_* FP的帖子

从后面的代码附加Image/ImageBrush

我正在尝试添加一个Image作为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;
            }
Run Code Online (Sandbox Code Playgroud)

我在尝试附加图像时遇到了同样的问题......我想这也取决于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);
        }

    } …
Run Code Online (Sandbox Code Playgroud)

c# win-universal-app windows-10-mobile uwp

5
推荐指数
1
解决办法
3875
查看次数

标签 统计

c# ×1

uwp ×1

win-universal-app ×1

windows-10-mobile ×1