I have an interface for a UI widget, two of which are attributes of a presenter.
public IMatrixWidget NonProjectActivityMatrix {
set {
// validate the incoming value and set the field
_nonProjectActivityMatrix = value;
....
// configure & load non-project activities
}
public IMatrixWidget ProjectActivityMatrix {
set {
// validate the incoming value and set the field
_projectActivityMatrix = value;
....
// configure & load project activities
}
The widget has an event that both presenter objects subscribe to, and so there is an event handler in the presenter like so:
public void OnActivityEntry(object sender, EntryChangedEventArgs e) {
// calculate newTotal here
....
if (ReferenceEquals(sender, _nonProjectActivityMatrix)) {
_nonProjectActivityMatrix.UpdateTotalHours(feedback.ActivityTotal);
}
else if (ReferenceEquals(sender, _projectActivityMatrix)) {
_projectActivityMatrix.UpdateTotalHours(feedback.ActivityTotal);
}
else {
// ERROR - we should never be here
}
}
The problem is that the ReferenceEquals on the sender fails, even though it is the implemented widget that is the sender - the same implemented widget that was set to the presenter attribute!
Can anyone spot what the problem / fix is?
Cheers,
Berryl
I didn't know you could edit nicely. Cool. Here is the event raising code:
void OnGridViewNumericUpDownEditingControl_ValueChanged(object sender, EventArgs e)
{
// omitted to save sapce
if (EntryChanged == null) return;
var args = new EntryChangedEventArgs(activityID, dayID, Convert.ToDouble(amount));
EntryChanged(this, args);
}
Here is the debugger dump of the presenter attribute, sans namespace info:
?_nonProjectActivityMatrix
{WinPresentation.Widgets.MatrixWidgetDgv}
[WinPresentation.Widgets.MatrixWidgetDgv]: {WinPresentation.Widgets.MatrixWidgetDgv}
Here is the debugger dump of the sender:
?sender
{WinPresentation.Widgets.MatrixWidgetDgv}
base {Core.GUI.Widgets.Lookup.MatrixWidgetBase<Core.GUI.Widgets.Lookup.DynamicDisplayDto>}: {WinPresentation.Widgets.MatrixWidgetDgv}
_configuration: {Domain.Presentation.Timesheet.Matrix.WeeklyMatrixConfiguration}
_wrappedWidget: {Win.Widgets.DataGridViewDynamicLookupWidget}
AllowUserToAddRows: true
ColumnCount: 11
Count: 4
EntryChanged: {Method = {Void OnActivityEntry(System.Object, Smack.ConstructionAdmin.Domain.Presentation.Timesheet.Matrix.EntryChangedEventArgs)}}
SelectedCell: {DataGridViewNumericUpDownCell { ColumnIndex=3, RowIndex=3 }}
SelectedCellValue: "0.00"
SelectedColumn: {DataGridViewNumericUpDownColumn { Name=MONDAY, Index=3 }}
SelectedItem: {'AdministrativeActivity: 130-04', , AdministrativeTime, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}
Berryl