任何人都可以告訴我如何連接編程創建的列表中的複選框的單擊事件?到目前爲止,我只看到連接靜態創建的對象事件的例子,而不是從代碼動態分配的事件。c#編程式創建列表事件處理程序howto
如下面的代碼片段描述創建的列表:
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>