【发布时间】:2016-04-26 22:30:09
【问题描述】:
如何在 XAML 中显示未知数量的复选框?我正在查询数据库以提取可能值的列表,然后我想将这些值显示为复选框列表。一些数据库表可能有少量值,其他可能有 100+。
XAML:
<ListBox x:Name="SuppliersSearchStatusListBox" Margin="100,100,0,0" ScrollViewer.CanContentScroll="True" AllowDrop="True" MaxHeight="50" MaxWidth="200" HorizontalAlignment="Left" VerticalAlignment="Top" ItemsSource="{Binding ListStatusOptions}">
<CheckBox Content="{Binding arrStatusOption}"/>
</ListBox>
CS:
public void ListStatusOptions()
{
// Query, vars and debug info removed
conn.Open();
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQLQuery, conn);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "StatusOptions");
int varArrCount = ds.Tables[0].Rows.Count;
string[] arrStatusOption = new string[varArrCount];
int i = 0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
arrStatusOption[i] = dr["StatusValue"].ToString();
i++;
}
conn.Close();
}
DB 查询将结果返回到数组中,并且值与预期的一样,但复选框列表不会出现在 XAML 页面上。我错过了什么?
【问题讨论】:
标签: c# wpf database xaml checkbox