我试图弄清楚如何修改嵌入在 ListView/GridView 中的复选框的状态。问题是该复选框取决于单独 DataGrid 中某些记录的批准状态。(例如,我使用复选框作为批准状态 True = 全部批准,False = 无,null = 部分批准)。
由于 DataContext 是一个实体,它没有我可以用来处理它的布尔值。
<ListView x:Name="EmployeeNameListBox" Height="330" ItemsSource="{Binding}" SelectedValuePath="ID" SelectionChanged="EmployeeNameListBoxSelectionChanged">
<ListView.View>
<GridView AllowsColumnReorder="False" >
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsThreeState="True" Checked="EmployeeCheckBoxChecked" Unchecked="EmployeeCheckBoxChecked" x:Name="CheckBoxHero"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1} - {2}">
<Binding Path="LastName" />
<Binding Path="FirstName" />
<Binding Path="EmployeeNumber" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
这是我尝试更新审批状态的地方:
foreach (var employee in this.employees)
{
var records = from a in this.dailyActivities where a.Employee == employee select a;
var approvedRecords = from r in records where r.IsApproved == true select r;
if (approvedRecords.Count() == 0)
{
// None Approved checkbox state = false
}
else if (approvedRecords.Count() == records.Count())
{
// All Approved checkbox state = true
}
else
{
// Some Approved Set Checkbox state to null
}
}