【发布时间】:2011-10-21 11:57:15
【问题描述】:
我对 wpf 有一点疑问,我在按钮上保留了图像。所以当我们单击按钮时,应该将图像设置为背景?我该怎么办?任何人有想法> 请告诉我。
提前感谢 开发者
【问题讨论】:
-
如果您没有更清楚地表达自己对自己拥有的东西(可能提供代码)和想要的东西的帮助。
-
按钮上的图像很好,不需要特殊操作。
标签: c# wpf desktop-application
我对 wpf 有一点疑问,我在按钮上保留了图像。所以当我们单击按钮时,应该将图像设置为背景?我该怎么办?任何人有想法> 请告诉我。
提前感谢 开发者
【问题讨论】:
标签: c# wpf desktop-application
如果您需要将图像作为任何控件(按钮或网格,您不理解)的背景,只需在代码中将 Background 属性设置为带有图像 ImageSource 的 ImageBrush。
【讨论】:
此代码用于按钮,编辑它...
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);
这可能你...
【讨论】: