无法在 silverlight 中创建按钮数组?
这是我使用的代码,但我不确定为什么它可以通过我在窗口形式中完成的方式来实现。
Button[] btnMonday = new Button[20];
string[] timeslot = { "08:00 AM", "08:30 AM", "09:00 AM", "09:30 AM", "10:00 AM", "10:30 AM", "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", "01:00 PM", "01:30 PM", "02:00 PM", "02:30 PM", "03:00 PM", "03:30 PM", "04:00 PM", "04:30 PM", "05:00 PM", "05:30 PM" };
#region Monday
for (int i = 0; i < 20; i++)
{
btnMonday[i].SetValue(Height, 38);
btnMonday[i].SetValue(Width, 256);
btnMonday[i].SetValue(Content, timeslot[i]);
btnMonday[i].SetValue(Background, 0xFF, 0xB1, 0xB1, 0xB1);
// Sets dependency properties
btnMonday[i].SetValue(Grid.ColumnProperty, 0);
btnMonday[i].SetValue(Grid.RowProperty, i + 1);
// Adds the dynamically created control to the canvas
LayoutRoot.Children.Add(btnMonday[i]);
}
更新
我仍然收到这部分代码的错误 ::
Button[] btnMonday = new Button[20];
string[] timeslot = { "08:00 AM", "08:30 AM", "09:00 AM", "09:30 AM", "10:00 AM", "10:30 AM", "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", "01:00 PM", "01:30 PM", "02:00 PM", "02:30 PM", "03:00 PM", "03:30 PM", "04:00 PM", "04:30 PM", "05:00 PM", "05:30 PM" };
#region Monday
for (int i = 0; i < 20; i++)
{
btnMonday[i] = new Button();
btnMonday[i].SetValue(Height, 38);
btnMonday[i].SetValue(Width, 256);
btnMonday[i].SetValue(Content, timeslot[i]);
// Sets dependency properties
btnMonday[i].SetValue(Grid.ColumnProperty, 0);
btnMonday[i].SetValue(Grid.RowProperty, i + 1);
// Adds the dynamically created control to the canvas
LayoutRoot.Children.Add(btnMonday[i]);
}
是否有可能出现语法错误?我可以知道如何设置按钮的背景值吗?它似乎不适用于以前的定义背景颜色的样式。我得到的错误::
Error 2 Argument 1: cannot convert from 'double' to 'System.Windows.DependencyProperty'
以及
Error 1 The best overloaded method match for 'System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty, object)' has some invalid arguments
这几行
btnMonday[i].SetValue(Height, 38);
btnMonday[i].SetValue(Width, 256);
btnMonday[i].SetValue(Content, timeslot[i]);
btnMonday[i].SetValue(Background, 0xFF, 0xB1, 0xB1, 0xB1);
This is the code i using, but i not sure why it can be implement via the way i done in window form.
Button[] btnMonday = new Button[20];
string[] timeslot = { "08:00 AM", "08:30 AM", "09:00 AM", "09:30 AM", "10:00 AM", "10:30 AM", "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", "01:00 PM", "01:30 PM", "02:00 PM", "02:30 PM", "03:00 PM", "03:30 PM", "04:00 PM", "04:30 PM", "05:00 PM", "05:30 PM" };
#region Monday
for (int i = 0; i < 20; i++)
{
btnMonday[i].SetValue(Height, 38);
btnMonday[i].SetValue(Width, 256);
btnMonday[i].SetValue(Content, timeslot[i]);
btnMonday[i].SetValue(Background, 0xFF, 0xB1, 0xB1, 0xB1);
// Sets dependency properties
btnMonday[i].SetValue(Grid.ColumnProperty, 0);
btnMonday[i].SetValue(Grid.RowProperty, i + 1);
// Adds the dynamically created control to the canvas
LayoutRoot.Children.Add(btnMonday[i]);
}
update
i still getting error with this portion of code ::
Button[] btnMonday = new Button[20];
string[] timeslot = { "08:00 AM", "08:30 AM", "09:00 AM", "09:30 AM", "10:00 AM", "10:30 AM", "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", "01:00 PM", "01:30 PM", "02:00 PM", "02:30 PM", "03:00 PM", "03:30 PM", "04:00 PM", "04:30 PM", "05:00 PM", "05:30 PM" };
#region Monday
for (int i = 0; i < 20; i++)
{
btnMonday[i] = new Button();
btnMonday[i].SetValue(Height, 38);
btnMonday[i].SetValue(Width, 256);
btnMonday[i].SetValue(Content, timeslot[i]);
// Sets dependency properties
btnMonday[i].SetValue(Grid.ColumnProperty, 0);
btnMonday[i].SetValue(Grid.RowProperty, i + 1);
// Adds the dynamically created control to the canvas
LayoutRoot.Children.Add(btnMonday[i]);
}
is there any possibility of syntac error ?? and may i know how to set value of background to button ?? it seem not work well with the previous style of define background color.The error i get ::
Error 2 Argument 1: cannot convert from 'double' to 'System.Windows.DependencyProperty'
and
Error 1 The best overloaded method match for 'System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty, object)' has some invalid arguments
for this few line
btnMonday[i].SetValue(Height, 38);
btnMonday[i].SetValue(Width, 256);
btnMonday[i].SetValue(Content, timeslot[i]);
btnMonday[i].SetValue(Background, 0xFF, 0xB1, 0xB1, 0xB1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您坚持使用 SetValue 方法,请尝试以下操作:
if you insist using SetValue method, try this:
试试这个
try this