我希望我的复选框显示为按钮。复选框是使用C#在代码隐藏文件中动态生成的。
我该怎么做?
答案 0 :(得分:0)
private void loadItems() {
SqlConnection con = new SqlConnection();
con.ConnectionString = "ConString";
con.Open();
SqlCommand cmd = new SqlCommand("Select ItemId,ItemName from ITEMS", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
iid = (dt.Rows[i]["ItemId"]).ToString();
iname = dt.Rows[i]["ItemName"].ToString();
CheckBox btn = new CheckBox();
btn.Content = iname;
btn.Height = 20;
btn.Width = 150;
btn.Tag = iname;
//var2 = btn.Tag.ToString();
wrapItems.Children.Add(btn);
btn.Click += new RoutedEventHandler(CheckBoxChecked);
//btn.RaiseEvent(new RoutedEventArgs(Button.btnClick(sender,e)));
con.Close();
}