private object ApplyValueConverterSourceToTarget(object value) { if (_description.Converter == null) { return(value); } try { return (_description.Converter.Convert(value, TargetType, _description.ConverterParameter, CultureInfo.CurrentUICulture)); } catch (Exception exception) { // pokemon exception - force the use of Fallback in this case // we expect this exception to occur sometimes - so only "Diagnostic" level logging here MvxBindingLog.Trace( "Problem seen during binding execution for {0} - problem {1}", _description.ToString(), exception.ToLongString()); } return(MvxBindingConstant.UnsetValue); }
public virtual void FillFrom(IMvxNamedInstanceRegistry <T> registry, Assembly assembly) { var pairs = from type in assembly.ExceptionSafeGetTypes() where type.GetTypeInfo().IsPublic where !type.GetTypeInfo().IsAbstract where typeof(T).IsAssignableFrom(type) let name = FindName(type) where !string.IsNullOrEmpty(name) where type.IsConventional() select new { Name = name, Type = type }; foreach (var pair in pairs) { try { if (pair.Type.ContainsGenericParameters) { continue; } var converter = Activator.CreateInstance(pair.Type) as T; MvxBindingLog.Trace("Registering value converter {0}:{1}", pair.Name, pair.Type.Name); registry.AddOrOverwrite(pair.Name, converter); } catch (Exception) { // ignore this } } }
public override void SetValue(object value) { MvxBindingLog.Trace("Receiving SetValue to " + (value ?? "")); var target = Target; if (target == null) { MvxBindingLog.Warning("Weak Target is null in {0} - skipping set", GetType().Name); return; } if (ShouldSkipSetValueForPlatformSpecificReasons(target, value)) { return; } if (ShouldSkipSetValueForViewSpecificReasons(target, value)) { return; } var safeValue = MakeSafeValue(value); // to prevent feedback loops, we don't pass on 'same value' updates from the source while we are updating it if (_isUpdatingSource) { if (safeValue == null) { if (_updatingSourceWith == null) { return; } } else { if (safeValue.Equals(_updatingSourceWith)) { return; } } } try { _isUpdatingTarget = true; SetValueImpl(target, safeValue); } finally { _isUpdatingTarget = false; } }
protected override void SetValueImpl(object target, object value) { MvxBindingLog.Trace("Receiving setValue to " + (value ?? "")); var frameworkElement = target as FrameworkElement; if (frameworkElement == null) { MvxBindingLog.Warning("Weak Target is null in {0} - skipping set", GetType().Name); return; } frameworkElement.SetValue(_targetDependencyProperty, value); }
protected override void SetValueImpl(object target, object value) { MvxBindingLog.Trace("Receiving setValue to " + (value ?? "")); var bindableObject = target as BindableObject; if (bindableObject == null) { MvxBindingLog.Warning("Weak Target is null in {0} - skipping set", GetType().Name); return; } bindableObject.SetValue(_targetBindableProperty, value); }
// Note - this is public because we use it in weak referenced situations public void OnValueChanged(object sender, EventArgs eventArgs) { var target = Target; if (target == null) { MvxBindingLog.Trace("Null weak reference target seen during OnValueChanged - unusual as usually Target is the sender of the value changed. Ignoring the value changed"); return; } var value = TargetPropertyInfo.GetGetMethod().Invoke(target, null); FireValueChanged(value); }
protected IMvxValueConverter FindConverter(string converterName) { if (converterName == null) { return(null); } var toReturn = ValueConverterLookup.Find(converterName); if (toReturn == null) { MvxBindingLog.Trace("Could not find named converter for {0}", converterName); } return(toReturn); }
private void UpdateTargetOnBind() { if (NeedToUpdateTargetOnBind && _sourceStep != null) { _cancelSource.Cancel(); _cancelSource = new CancellationTokenSource(); var cancel = _cancelSource.Token; try { var currentValue = _sourceStep.GetValue(); UpdateTargetFromSource(currentValue, cancel); } catch (Exception exception) { MvxBindingLog.Trace("Exception masked in UpdateTargetOnBind {0}", exception.ToLongString()); } } }
protected MvxPropertyInfoSourceBinding(object source, PropertyInfo propertyInfo) : base(source) { _propertyInfo = propertyInfo; _propertyName = propertyInfo.Name; if (Source == null) { MvxBindingLog.Trace( "Unable to bind to source as it's null" , _propertyName); return; } var sourceNotify = Source as INotifyPropertyChanged; if (sourceNotify != null) { _subscription = sourceNotify.WeakSubscribe(SourcePropertyChanged); } }
protected sealed override void FireValueChanged(object newValue) { // we don't allow 'reentrant' updates of any kind from target to source if (_isUpdatingTarget || _isUpdatingSource) { return; } MvxBindingLog.Trace("Firing changed to " + (newValue ?? "")); try { _isUpdatingSource = true; _updatingSourceWith = newValue; base.FireValueChanged(newValue); } finally { _isUpdatingSource = false; _updatingSourceWith = null; } }
private EventInfo GetNamedPropertyChangedEvent(Type viewType, string propertyName) { var eventName = propertyName + "Changed"; var eventInfo = viewType.GetEvent(eventName); if (eventInfo == null) { return(null); } if (eventInfo.EventHandlerType != typeof(EventHandler)) { MvxBindingLog.Trace("Diagnostic - cannot two-way bind to {0}/{1} on type {2} because eventHandler is type {3}", viewType, eventName, viewType.Name, eventInfo.EventHandlerType.Name); return(null); } return(eventInfo); }
private string UnabbreviateTagName(string tagName) { var filteredTagName = tagName; if (ViewNamespaceAbbreviations != null) { var split = tagName.Split(new[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries); if (split.Length == 2) { var abbreviate = split[0]; string fullName; if (ViewNamespaceAbbreviations.TryGetValue(abbreviate, out fullName)) { filteredTagName = fullName + "." + split[1]; } else { MvxBindingLog.Trace("Abbreviation not found {0}", abbreviate); } } } return(filteredTagName); }