开发者

How set dynamically windows back ground image in wpf

开发者 https://www.devze.com 2023-03-26 03:44 出处:网络
I have small doubt in wpf,i kept image on button.so when we click on button that image should be set as back ground?what should i do? an开发者_StackOverflow中文版y one have idea>

I have small doubt in wpf,i kept image on button.so when we click on button that image should be set as back ground?what should i do? an开发者_StackOverflow中文版y one have idea> please let me know.

Thanks in Adavance Developer


If you need to put an image as a background of any control (button or grid, didn't understancd you), just set, in code, the Background property to an ImageBrush with an ImageSource of your image.


This code is for button, edit it ...

Button button = new Button();
button.Margin = new Thickness(220, -880, 0, 0);
button.Width = w;
button.Height = h;
/////////////////////////////////////////////////////////
ImageBrush berriesBrush = new ImageBrush();
berriesBrush.ImageSource = new BitmapImage(new Uri(@"Image/country.PNG", UriKind.Relative));
button.Background = berriesBrush;
button.BorderThickness = new Thickness(0);

This might you ...

0

精彩评论

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