Change WPF window background image in C# code

后端 未结 7 1656
梦毁少年i
梦毁少年i 2020-12-09 08:11

I have a couple of Images configured as application resources.

When my application starts, the background of the main window is set via XAML:



        
7条回答
  •  一生所求
    2020-12-09 08:59

    Uri resourceUri = new Uri(@"/cCleaner;component/Images/cleanerblack.png", UriKind.Relative);
                StreamResourceInfo streamInfo = Application.GetResourceStream(resourceUri);
                BitmapFrame temp = BitmapFrame.Create(streamInfo.Stream);
                var brush = new ImageBrush();
                brush.ImageSource = temp;
                frame8.Background = brush;
    

提交回复
热议问题