我有一个绑定到包含 itemsource 的项目列表的数据网格。复选框控件是网格上的一列,选中后将在单击按钮时存储特定信息。我的问题是我无法让对象checkBox
绑定到 XAML 复选框,当我检查checkbox
它时,它给了我一个空值或 false。
复选框的 XAML:
<DataGridTemplateColumn Header="Ist aktiv">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path= checkBox }" Name="checkBox" IsEnabled="{Binding Enabled}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn
>
按钮事件:
private void checkinCheckBox() {
List<AwaitingMeds> awaitingMedslist = MedicationDatagrid.ItemsSource as List<AwaitingMeds>;
//List<AwaitingMeds> awaitingMedslistSelected = new List<AwaitingMeds>();
List<AwaitingMeds> awaitingMedslistSelected = ( from m in awaitingMedslist
where m.checkBox.Equals( true )
select m ).ToList<AwaitingMeds>();
foreach( AwaitingMeds checkedItems in awaitingMedslistSelected )
{
MedicationDispenseData.UpdateMedicationDispense( checkedItems.MedicationDispenseID, ( int )Enumerations.MedicationDispenseStatus.CheckedIn,false, "" );
MedicationDispenseHistory medicationDispenseHistory = new MedicationDispenseHistory();
medicationDispenseHistory.MedicationDispenseID = checkedItems.MedicationDispenseID;
medicationDispenseHistory.StaffID = GlobalVariables.loggedInStaff.StaffID;
medicationDispenseHistory.MedicationDispenseStatusID = ( int )Enumerations.MedicationDispenseStatus.CheckedIn;
MedicationDispenseHistoryData.Create( medicationDispenseHistory );
}
}
public IEnumerable<DataGridRow> GetDataGridRows(DataGrid grid )
{
var itemsSource = grid.ItemsSource as System.Collections.IEnumerable;
if( null == itemsSource ) yield return null;
foreach( var item in itemsSource )
{
var row = grid.ItemContainerGenerator.ContainerFromItem( item ) as DataGridRow;
if( null != row ) yield return row;
}
}