谁能告诉我如何在以编程方式创建的列表中连接复选框的单击事件?到目前为止,我只看到了连接静态创建而不是从代码动态分配的对象的事件的示例。
该列表的创建如下面的片段中所述:
namespace CustomListApp
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
for (int i = 1; i <= 10; ++i)
{
CustomListBoxItem clbi = new CustomListBoxItem();
clbi.Title.Text = "This is item " + i;
clbi.Condition.IsChecked = i % 2 == 0;
CustomListBox.Items.Add(clbi);
}
}
}
}
并且 CustomListBoxItem 具有以下结构:
<UserControl x:Class="CustomListApp.CustomListBoxItem"[...]>
<Grid x:Name="ListBoxItemGrid" Background="{StaticResource PhoneChromeBrush}" Height="65">
<CheckBox x:Name="Condition" Height="67" HorizontalAlignment="Right" VerticalAlignment="Top" Width="65" Click="Condition_Click" />
<TextBlock x:Name="Title" Height="65" HorizontalAlignment="Left" Margin="84,0,0,0" Text="TextBlock" VerticalAlignment="Center" Width="294" />
</Grid>
</UserControl>