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); }
public ApplyValueResult TryApplyToInstance() { object newValue; if (HasUserChangedAnything) { if (mContainer.TryGetValueOnUi(out newValue) == 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); return(mContainer.TrySetValueOnInstance(newValue)); } } return(ApplyValueResult.Success); }
internal void CallBeforeSetByUi(IDataUi dataUi) { if (BeforeSetByUi != null) { BeforePropertyChangedArgs args = new BeforePropertyChangedArgs(); object value; dataUi.TryGetValueOnUi(out value); args.NewValue = value; BeforeSetByUi(this, args); if (args.WasManuallySet) { // The event changed it, so let's force it back on the UI dataUi.TrySetValueOnUi(args.OverridingValue); } } }
public static ApplyValueResult TrySetValueOnInstance(this IDataUi dataUi) { ApplyValueResult result; bool hasErrorOccurred; GetIfValuesCanBeSetOnInstance(dataUi, out result, out hasErrorOccurred); if (!hasErrorOccurred) { object valueOnUi; result = dataUi.TryGetValueOnUi(out valueOnUi); if (result == ApplyValueResult.Success) { dataUi.InstanceMember.Value = valueOnUi; result = ApplyValueResult.Success; dataUi.InstanceMember.CallAfterSetByUi(); } } return(result); }
internal void CallBeforeSetByUi(IDataUi dataUi) { if (BeforeSetByUi != null) { BeforePropertyChangedArgs args = new BeforePropertyChangedArgs(); object value; dataUi.TryGetValueOnUi(out value); args.NewValue = value; BeforeSetByUi(this, args); if (args.WasManuallySet) { // The event changed it, so let's force it back on the UI dataUi.TrySetValueOnUi(args.OverridingValue); } } }