开发者

How to set a background image for a window by clicking on the cntl button using wpf?

开发者 https://www.devze.com 2023-03-26 08:18 出处:网络
I want to set an image as background by clicking the开发者_如何学编程 ctrl button? Any one have ideas? please revert me ASAP.

I want to set an image as background by clicking the开发者_如何学编程 ctrl button?

Any one have ideas? please revert me ASAP.

Thanks in advance.


On button click event apply the following code

 ImageBrush myBrush = new ImageBrush();
    myBrush.ImageSource =
        new BitmapImage(new Uri(@"Image Path"));
    this.Background = myBrush;

You can replace the this with your control name


You can try the following code:

private void button1_Click(object sender, RoutedEventArgs e)
{
    BitmapImage imageSource = new BitmapImage(new Uri(@"Path/to/image.jpg"));

    ImageBrush brush = new ImageBrush();
    brush.ImageSource = imageSource;
    grid.Background = brush;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消