// TODO this is very fishy. // In effect we now have a custom class that responds to UI changes // The underlying idea is that filters will update automagically, // at least I think that that is the general idea // I am pretty convinced now it is a BAD idea // we should leave this kind of model-changing stuff to the model private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e) { // do not update properties that we update ourselves // this code will not win prizes :) if (e.PropertyName.Equals(nameof(_model.CurrentFilter)) || e.PropertyName.Equals(nameof(_model.IsValid))) { return; } // we want to update the filter according to its type switch (_filter) { case CursorFilterTypeF _filter: _filter = ConstructFFilter(_filter, _model); break; case CursorFilterTypeCTI _filter: _filter = ConstructCTIFilter(_filter, _model); break; case CursorFilterTypeCTCF _filter: _filter = ConstructCTCFFilter(_filter, _model); break; case CursorFilterTypeCTCTI _filter: _filter = ConstructCTCTIFilter(_filter, _model); break; } _model.CurrentFilter = _filter; // pass back the updated filter to the model. BAD IDEA FilterValidator fv = new FilterValidator(_filter); _model.IsValid = fv.Validate(); // ALSO BAD IDEA // here would be a place we can put in our FilterString builder so the // textbox would not have to pass a control to ConverterParam, // but instead just be bound to a property }
// TODO this is very fishy. // In effect we now have a custom class that responds to UI changes // The underlying idea is that filters will update automagically, // at least I think that that is the general idea // I am pretty convinced now it is a BAD idea // we should leave this kind of model-changing stuff to the model private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e) { // do not update properties that we update ourselves // this code will not win prizes :) if (e.PropertyName.Equals(nameof(_model.CurrentFilter)) || // not needed e.PropertyName.Equals(nameof(_model.FilterString)) || e.PropertyName.Equals(nameof(_model.IsValid))) { return; } // we want to update the filter according to its type switch (_filter) { case CursorFilterTypeF _filter: _filter = ConstructFFilter(_filter, _model); break; case CursorFilterTypeCTI _filter: _filter = ConstructCTIFilter(_filter, _model); break; case CursorFilterTypeCTCF _filter: _filter = ConstructCTCFFilter(_filter, _model); break; case CursorFilterTypeCTCTI _filter: _filter = ConstructCTCTIFilter(_filter, _model); break; } _model.CurrentFilter = _filter; // pass back the updated filter to the model. FilterValidator fv = new FilterValidator(_filter); _model.IsValid = fv.Validate(); _model.FilterString = FilterStringCreator.ToString(_filter, _model.OutputFormat); }