I have two columns in my data source that is editable and is a boolean value. My data object implement INotifyPropertyChanged. Two questions:
1. When I initially run the app, all checkboxes are kinda grayed out, in some intermediate state, even though my data objects certain have values fro those boolean properties. How can I make sure they properly load?
2. The value of one bool depends on the other. The two properties cannot be true, but any other combination is possible. To this end, my data object has logic so if: valA is set to true, if valB is true, property valB is set to false and vice-versa. The issue is that the actual setter is not called by the Check Editor until the checkbox is unfocused. What's my best way to go around this? Should I attach custom event handlers to valuechanged? Should I create an unbound column and create a control template that displays my own custom checkbox with custom handlers?
Thanks,
-Szymon
For now, I'm using the following workaround:
1. Add the following Field settings to my boolean fields:
<igDP:Field.Settings> <igDP:FieldSettings AllowEdit="True" EditAsType="{x:Type sys:Boolean}" EditorType="{x:Type igEditors:XamCheckEditor}" LabelWidth="60" CellWidth="60"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamCheckEditor}"> <EventSetter Event="ValueChanged" Handler="HandleValueChangedAccept" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings>
and:
<igDP:Field.Settings> <igDP:FieldSettings AllowEdit="True" EditAsType="{x:Type sys:Boolean}" EditorType="{x:Type igEditors:XamCheckEditor}" LabelWidth="60" CellWidth="60" > <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamCheckEditor}"> <EventSetter Event="ValueChanged" Handler="HandleValueChangedRollback" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings>
I am hooking a handler to the ValueChanged event on the XamCheckEditor.
2. Implement the handling methods:
void HandleValueChangedAccept(object sender, RoutedPropertyChangedEventArgs<object> e) { bool newValue = (bool)e.NewValue; if (!newValue) return; DependencyObject o = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordCellArea), true); DataRecordCellArea dataRecord = o as DataRecordCellArea; if (dataRecord == null) return; DAO dao = dataRecord.Record.DataItem as DAO ; dao.Accept = (bool)e.NewValue; } void HandleValueChangedRollback(object sender, RoutedPropertyChangedEventArgs<object> e) { bool newValue = (bool)e.NewValue; if (!newValue) return; DependencyObject o = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordCellArea), true); DataRecordCellArea dataRecord = o as DataRecordCellArea; if (dataRecord == null) return; DAO dao = dataRecord.Record.DataItem as DAO ; dao .Rollback = (bool)e.NewValue; }
Notice that my logic dictates that two values cannot be set to true. My DAO setters handle this logic. But this creates an opportunity for an infinite loop. Since dao.Rollback may change the value of dao.Accept, the ValueChanged handlers for the checkboxes may keep on calling each other infinitely. For this purpose, I make sure that the handler doesn't do anything if the new value is false.
So this is a bit of a hackish way to do this, but it works. Chris, let me know if there's a more elegant way to do this using the UpdateSourceTrigger property of the internal binding.
I see the issue you are talking about. The internal binding UpdateSourceTrigger needs to be changed from the default "LostFocus" to "PropertyChanged". I will look into how to do this and post the solution.
I installed the hot fix. I no longer see the initial load problem in which the checkboxes are grayed out (issue #1), but I still have issue #2.
Are you really not seeing the same issue? To reiterate, both checkboxes cannot be checked at the same time. Ever. What I am seeing now is that I can have that intermediate state when I click on a checkbox. Only after I unfocus from the checkbox does the setter get called, and my logic get invoked.
Szymon,
Thank you for the sample.
Two thoughts:
Use ObservableCollection instead of ILIst. ObservableCollection is an ILIst which works better with dynamic updating.
Have you installed the 7.2 HotFix? I am not having an update problem with the sample you sent me.
Thanks
Ok. I have attached a project that replicates both issues I am seeing. So basically I'm not doing any of the binding myself; I let the grid do it for me. In my actual xaml, I define my own field, editor types and edit as, but the behavior is exactly the same as allowing the grid to create the fields on its own.