public ApplyValueResult TryApplyToInstance() { object newValue; if (HasUserChangedAnything) { var result = mContainer.TryGetValueOnUi(out newValue); if (result == ApplyValueResult.Success) { if (InstanceMember.BeforeSetByUi != null) { InstanceMember.CallBeforeSetByUi(mContainer); } // Hold on, the Before set may have actually changed the value, so we should get the value again. mContainer.TryGetValueOnUi(out newValue); if (newValue is string) { newValue = (newValue as string).Replace("\r", ""); } // get rid of \r return(mContainer.TrySetValueOnInstance(newValue)); } else { if (InstanceMember.SetValueError != null) { InstanceMember.SetValueError(mAssociatedTextBox.Text); } } } return(ApplyValueResult.Success); }