我想在选中复选框时动态添加堆栈面板,如果未选中复选框,则我想删除该堆栈面板。我试过以下代码。 当我运行程序并检查复选框时,没有任何事情发生。
private void bCheckbox_Checked(object sender, RoutedEventArgs e)
{
var stackpanel = new StackPanel{ Orientation = Orientation.Vertical };
stackpanel.SetValue(Grid.RowProperty, 2);
stackpanel.SetValue(Grid.ColumnProperty, 1);
var textblockstart = new TextBlock { Text = "loop start time", FontSize = 18,
Margin = new Thickness(20,20,0,0)};
var textboxstart = new TextBox { Name = "StartTextBox", Height=27, Width=110,
Margin = new Thickness(20,10,0,0) };
var textblockend = new TextBlock { Text = "loop end time", FontSize = 18,
Margin = new Thickness(20,20,0,0)};
var textboxend = new TextBox { Name = "EndTextBox", Height=27, Width=110,
Margin = new Thickness(20,10,0,0) };
stackpanel.Children.Add(textblockstart);
stackpanel.Children.Add(textboxstart);
stackpanel.Children.Add(textblockend);
stackpanel.Children.Add(textboxend);
}
答案 0 :(得分:1)
您可以执行的操作是在using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Configuration;
[System.Web.Services.WebMethod]
public static List<string> GetCities(string prefixText)
{
SqlConnection con = new SqlConnection
(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("select * from City where CityName
like @Name+'%'", con);
cmd.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<string> CoityNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CityNames.Add(dt.Rows[i][1].ToString());
}
return CityNames;
}
设置为StackPanel
的情况下在xaml标记中创建Visibility
,并在切换事件中切换Collapsed
的可见性StackPanel