我想弄清楚如何修改嵌入在ListView/GridView中的複選框的狀態。問題在於複選框取決於單獨DataGrid中某些記錄的審批狀態。 (例如,我使用複選框作爲批准狀態True =全部批准,False =無,null =部分批准)。訪問ListView複選框
由於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
}
}
Silverlight? WPF?請添加更多標籤 – Shyju
如果它沒有bool值,爲什麼不創建一個包裝對象(可能稱之爲viewmodel)並綁定到該類中的值呢? – Patrick
我最終剛剛在另一個部分類中實現了該變量。似乎工作正常,我只是想避免部分類,因爲我只需要它爲這一個控制。 – TheButlerDidIt