【发布时间】:2016-03-26 16:33:00
【问题描述】:
我从列表中创建了几个按钮,我现在需要更改其中一个按钮的图像。 我现在正在尝试将字符串转换为按钮。 我如何获取字符串并将其转换为我可以使用的按钮?
我试过这个:
Button button = (Button)this.FindName("button_" + list[0].ToString());
button.background = brush;
当我调用 button.background 时,我得到一个对象引用未设置为对象实例的错误。
编辑 这就是我选择更改按钮图像的方式:
Uri resourceUri = new Uri("led_On.png", UriKind.Relative);
StreamResourceInfo streamInfo = Application.GetResourceStream(resourceUri);
BitmapFrame temp = BitmapFrame.Create(streamInfo.Stream);
var brush = new ImageBrush();
brush.ImageSource = temp;
Button button = (Button)FindName("button_" + list[0].ToString());
button.Background = brush;
我只是无法抓住名称为 button_list[0] 的按钮。
【问题讨论】:
-
什么是“这个”?这个按钮是这个的孩子吗?