我有一个列表视图,每个项目都有一个 CheckBox 控件作为其 ItemTemplate 的一部分。
<ListView x:Name="taskListView" Grid.Row="2" BorderThickness="0" Margin="30,0,0,0" ItemsSource="{Binding ChildItems}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<ColumnDefinition Width="290"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" HorizontalAlignment="Center"></CheckBox>
<TextBlock Text="{Binding Name}" MaxWidth="270" Grid.Column="1" Margin="0,0,10,0"/>
<ComboBox SelectedItem="{Binding DependentTask, Mode=TwoWay}"
Grid.Column="2"
Margin="0,3,0,3"
ItemsSource="{Binding DependentTasks, Converter={StaticResource addEmptyItemConverter}}"
HorizontalAlignment="Left"
MinWidth="150"
DisplayMemberPath="ProjectionTaskLink.Name"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
此 ListView 的父级也有一个复选框。检查该父复选框后,我想检查ListViewItems中的所有复选框。如何在 Codebehind 中获取这些内容,以便我可以根据父条件将它们设置为 Checked 或 Unchecked?
谢谢。
编辑:这是完整的 XAML:
<Grid Margin="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="20"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="35"/>
<ColumnDefinition Width="35"/>
</Grid.ColumnDefinitions>
<CheckBox HorizontalAlignment="Center" Grid.Column="0" Checked="CheckBox_Checked"/>
<TextBlock Text="{Binding Name}" Grid.Column="1"/>
<TextBlock Text="Loops " Grid.Column="2" TextAlignment="Center"/>
<TextBox Text="{Binding Scenarios}" Grid.Column="3"/>
</Grid>
<TextBlock Visibility="{Binding ContainsProjectionTasks, Converter={StaticResource boolToVisibilityConverter}}"
HorizontalAlignment="Left"
Width="450"
TextAlignment="Right"
VerticalAlignment="Bottom"
Grid.Row="1"
Text="Task Dependencies"
Background="White"/>
<ListView x:Name="taskListView" Grid.Row="2" BorderThickness="0" Margin="30,0,0,0" ItemsSource="{Binding ChildItems}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<ColumnDefinition Width="290"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" HorizontalAlignment="Center"></CheckBox>
<TextBlock Text="{Binding Name}" MaxWidth="270" Grid.Column="1" Margin="0,0,10,0"/>
<ComboBox SelectedItem="{Binding DependentTask, Mode=TwoWay}"
Grid.Column="2"
Margin="0,3,0,3"
ItemsSource="{Binding DependentTasks, Converter={StaticResource addEmptyItemConverter}}"
HorizontalAlignment="Left"
MinWidth="150"
DisplayMemberPath="ProjectionTaskLink.Name"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>