public override void SetValue(object value) { if (PropertyInfo == null) { MvxBindingLog.Warning("SetValue ignored in binding - source property {0} is missing", PropertyName); return; } if (!PropertyInfo.CanWrite) { MvxBindingLog.Warning("SetValue ignored in binding - target property {0}.{1} is readonly", PropertyInfo.DeclaringType?.Name, PropertyName); return; } try { var propertyType = PropertyInfo.PropertyType; var safeValue = propertyType.MakeSafeValue(value); // if safeValue matches the existing value, then don't call set if (EqualsCurrentValue(safeValue)) { return; } PropertyInfo.SetValue(Source, safeValue, PropertyIndexParameters()); } catch (Exception exception) { MvxBindingLog.Error("SetValue failed with exception - " + exception.ToLongString()); } }
protected override void SetValueImpl(object target, object value) { var imageView = (ImageView)target; if (!(value is string)) { MvxBindingLog.Warning( "Value '{0}' could not be parsed as a valid string identifier", value); imageView.SetImageDrawable(null); return; } var resources = AndroidGlobals.ApplicationContext.Resources; var id = resources.GetIdentifier((string)value, "drawable", AndroidGlobals.ApplicationContext.PackageName); if (id == 0) { MvxBindingLog.Warning( "Value '{0}' was not a known drawable name", value); imageView.SetImageDrawable(null); return; } base.SetValueImpl(target, id); }
public virtual View?CreateView(View?parent, string name, Context context, IAttributeSet attrs) { // resolve the tag name to a type var viewType = ViewTypeResolver?.Resolve(name); if (viewType == null) { //MvxBindingLog.Error( "View type not found - {0}", name); return(null); } try { var view = Activator.CreateInstance(viewType, context, attrs) as View; if (view == null) { MvxBindingLog.Error("Unable to load view {0} from type {1}", name, viewType.FullName ?? string.Empty); } return(view); } catch (ThreadAbortException) { throw; } catch (Exception exception) { MvxBindingLog.Error( "Exception during creation of {0} from type {1} - exception {2}", name, viewType.FullName ?? string.Empty, exception.ToLongString()); return(null); } }
protected override void SetValueImpl(object target, object value) { var listView = (MvxExpandableListView)target; if (value == null) { _currentValue = null; listView.ClearChoices(); return; } var positions = ((MvxExpandableListAdapter)listView.ExpandableListAdapter).GetPositions(value); if (positions == null) { MvxBindingLog.Warning("Value not found for spinner {0}", value.ToString()); return; } _currentValue = value; listView.SetSelectedChild(positions.Item1, positions.Item2, true); var pos = listView.GetFlatListPosition(ExpandableListView.GetPackedPositionForChild(positions.Item1, positions.Item2)); listView.SetItemChecked(pos, true); }
protected override void SetValueImpl(object target, object value) { var textView = (UITextView)target; if (value == null) { textView.AttributedText = new NSAttributedString(); return; } try { var text = value as NSAttributedString; if (text == null) { textView.AttributedText = new NSAttributedString(); return; } if (textView.TextAlignment != UITextAlignment.Natural && text.Length > 0) { text.EnumerateAttributes(new NSRange(0, text.Length - 1), NSAttributedStringEnumeration.None, new NSAttributedRangeCallback(ResetAlignment)); } text.EnumerateAttributes(new NSRange(0, text.Length - 1), NSAttributedStringEnumeration.None, new NSAttributedRangeCallback(FindLink)); textView.AttributedText = text; } catch (Exception e) { MvxBindingLog.Error("Failed to set font+language to UITextView. Binded value is null or not an AttributedString."); } }
public override void SubscribeToEvents() { var view = View; if (view == null) { MvxBindingLog.Error("Error - NSTabViewController is null in MvxNSTabViewControllerSelectedTabViewItemIndexTargetBinding"); return; } _subscribed = true; if (view is MvxEventSourceTabViewController) { ((MvxEventSourceTabViewController)view).DidSelectCalled += HandleValueChanged; } else { try { view.TabView.DidSelect += HandleValueChanged; } catch (Exception ex) { MvxBindingLog.Error(ex.Message); } } }
protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); if (isDisposing) { var view = View; if (view != null && _subscribed) { if (view is MvxEventSourceTabViewController) { ((MvxEventSourceTabViewController)view).DidSelectCalled -= HandleValueChanged; } else { try { view.TabView.DidSelect -= HandleValueChanged; } catch (Exception ex) { MvxBindingLog.Error(ex.Message); } } _subscribed = false; } } }
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 } } }
private static bool TryCreatePropertyDependencyBasedBinding(object target, string targetName, out IMvxTargetBinding binding) { if (target == null) { binding = null; return(false); } if (string.IsNullOrEmpty(targetName)) { MvxBindingLog.Error( "Empty binding target passed to MvxWindowsTargetBindingFactoryRegistry"); binding = null; return(false); } var dependencyProperty = target.GetType().FindDependencyProperty(targetName); if (dependencyProperty == null) { binding = null; return(false); } var actualProperty = target.GetType().FindActualProperty(targetName); var actualPropertyType = actualProperty?.PropertyType ?? typeof(object); binding = new MvxDependencyPropertyTargetBinding(target, targetName, dependencyProperty, actualPropertyType); return(true); }
protected virtual void SetItemsSource(IEnumerable value) { if (ReferenceEquals(_itemsSource, value) && !ReloadOnAllItemsSourceSets) { return; } _subscription?.Dispose(); _subscription = null; _itemsSource = value; if (_itemsSource != null && !(_itemsSource is IList)) { MvxBindingLog.Warning("Binding to IEnumerable rather than IList - this can be inefficient, especially for large lists"); } var newObservable = _itemsSource as INotifyCollectionChanged; if (newObservable != null) { _subscription = newObservable.WeakSubscribe(OnItemsSourceCollectionChanged); } NotifyDataSetChanged(); }
protected override void SetValueImpl(object target, object value) { var label = (UILabel)target; if (value == null) { label.AttributedText = new NSAttributedString(); return; } try { var text = value as NSAttributedString; if (text == null) { label.AttributedText = new NSAttributedString(); return; } //override the textalignment in case the view is not natural so that we can use the designer to deside the alignment (what you want in most cases) if (label.TextAlignment != UITextAlignment.Natural && text.Length > 0) { text.EnumerateAttributes(new NSRange(0, text.Length - 1), NSAttributedStringEnumeration.None, new NSAttributedRangeCallback(ResetAlignment)); } label.AttributedText = text; } catch (Exception e) { MvxBindingLog.Error("Failed to set font+language to UILabel. Binded value is null or not an AttributedString."); } }
protected override void SetValueImpl(object target, object value) { var view = this.View; if (view == null) { return; } var visibility = (MvxVisibility)value; switch (visibility) { case MvxVisibility.Visible: view.Hidden = false; break; case MvxVisibility.Collapsed: view.Hidden = true; break; default: MvxBindingLog.Warning("Visibility out of range {0}", value); break; } }
protected override void SetValueImpl(object target, object value) { var tf = (UITextView)target; Font font = value as Font; if (font != null) { try { tf.Font = TouchAssetPlugin.GetCachedFont(font); if (font.Color != System.Drawing.Color.Empty) { tf.TextColor = font.Color.ToNativeColor(); } if (font.Alignment != TextAlignment.None) { tf.TextAlignment = font.ToNativeAlignment(); } } catch { MvxBindingLog.Error("Failed to set font to UITextView. Check if font exists, has a size and filename, and is added to the plist"); } } }
private void UpdateTargetFromSource(object value, CancellationToken cancel) { if (value == MvxBindingConstant.DoNothing || cancel.IsCancellationRequested) { return; } if (value == MvxBindingConstant.UnsetValue) { value = _defaultTargetValue; } dispatcher.RequestMainThreadAction(() => { if (cancel.IsCancellationRequested) { return; } try { lock (_targetLocker) { _targetBinding?.SetValue(value); } } catch (Exception exception) { MvxBindingLog.Error( "Problem seen during binding execution for {0} - problem {1}", _bindingDescription.ToString(), exception.ToLongString()); } }); }
public IMvxSourceBinding CreateBinding(object source, IList <MvxPropertyToken> tokens) { if (tokens == null || tokens.Count == 0) { throw new MvxException("empty token list passed to CreateBinding"); } var currentToken = tokens[0]; var remainingTokens = tokens.Skip(1).ToList(); IMvxSourceBinding extensionResult; if (TryCreateBindingFromExtensions(source, currentToken, remainingTokens, out extensionResult)) { return(extensionResult); } if (source != null) { MvxBindingLog.Warning( "Unable to bind: source property source not found {0} on {1}" , currentToken , source.GetType().Name); } return(new MvxMissingSourceBinding(source)); }
public bool TryParseBindingSpecification(string text, out MvxSerializableBindingSpecification requestedBindings) { try { Reset(text); var toReturn = new MvxSerializableBindingSpecification(); while (!IsComplete) { SkipWhitespaceAndDescriptionSeparators(); var result = ParseTargetPropertyNameAndDescription(); toReturn[result.Key] = result.Value; SkipWhitespaceAndDescriptionSeparators(); } requestedBindings = toReturn; return(true); } catch (Exception exception) { MvxBindingLog.Error("Problem parsing binding {0}", exception.ToLongString()); requestedBindings = null; return(false); } }
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); }
private void RemoveHandler() { switch (_controlEvent) { case MvxIosPropertyBinding.UIControl_TouchDown: case MvxIosPropertyBinding.UIControl_TouchDownRepeat: case MvxIosPropertyBinding.UIControl_TouchDragInside: case MvxIosPropertyBinding.UIControl_TouchUpInside: case MvxIosPropertyBinding.UIControl_ValueChanged: case MvxIosPropertyBinding.UIControl_PrimaryActionTriggered: case MvxIosPropertyBinding.UIControl_EditingDidBegin: case MvxIosPropertyBinding.UIControl_EditingChanged: case MvxIosPropertyBinding.UIControl_EditingDidEnd: case MvxIosPropertyBinding.UIControl_EditingDidEndOnExit: case MvxIosPropertyBinding.UIControl_AllTouchEvents: case MvxIosPropertyBinding.UIControl_AllEditingEvents: case MvxIosPropertyBinding.UIControl_AllEvents: _controlEventSubscription?.Dispose(); break; default: MvxBindingLog.Error("Error - Invalid controlEvent in MvxUIControlTargetBinding"); break; } }
public MvxNSButtonTitleTargetBinding(NSButton button) : base(button) { if (button == null) { MvxBindingLog.Error("Error - NSButton is null in MvxNSButtonTitleTargetBinding"); } }
public MvxUIActivityIndicatorViewHiddenTargetBinding(UIActivityIndicatorView target) : base(target) { if (target == null) { MvxBindingLog.Error("Error - UIActivityIndicatorView is null in MvxUIActivityIndicatorViewHiddenTargetBinding"); } }
public MvxWithEventPropertyInfoTargetBinding(object target, PropertyInfo targetPropertyInfo) : base(target, targetPropertyInfo) { if (target == null) { MvxBindingLog.Error("Error - target is null in MvxWithEventPropertyInfoTargetBinding"); } }
public MvxUIButtonTitleTargetBinding(UIButton button, UIControlState state = UIControlState.Normal) : base(button) { _state = state; if (button == null) { MvxBindingLog.Error("Error - UIButton is null in MvxUIButtonTitleTargetBinding"); } }
private void ParseConverterParameter(string block, MvxSerializableBindingDescription description) { ParseEquals(block); if (description.ConverterParameter != null) { MvxBindingLog.Warning("Overwriting existing ConverterParameter"); } description.ConverterParameter = ReadValue(); }
private void ParseFallbackValue(string block, MvxSerializableBindingDescription description) { ParseEquals(block); if (description.FallbackValue != null) { MvxBindingLog.Warning("Overwriting existing FallbackValue"); } description.FallbackValue = ReadValue(); }
public MvxTextViewHtmlTextTargetBinding(WebView target) : base(target) { if (target == null) { MvxBindingLog.Error("Error - TextView is null in MvxTextViewTextTargetBinding"); return; } }
public MvxUILabelTextTargetBinding(UILabel target) : base(target) { if (target == null) { MvxBindingLog.Error( "Error - UILabel is null in MvxUILabelTextTargetBinding"); } }
public override void SetValue(object value) { if (_currentChildBinding == null) { MvxBindingLog.Warning("SetValue ignored in binding - target property path missing"); return; } _currentChildBinding.SetValue(value); }
public MvxAppCompatAutoCompleteTextViewSelectedObjectTargetBinding(object target, PropertyInfo targetPropertyInfo) : base(target, targetPropertyInfo) { var autoComplete = this.View; if (autoComplete == null) { MvxBindingLog.Error( "Error - autoComplete is null in MvxAppCompatAutoCompleteTextViewSelectedObjectTargetBinding"); } }
public MvxAutoCompleteTextViewPartialTextTargetBinding(object target, PropertyInfo targetPropertyInfo) : base(target, targetPropertyInfo) { var autoComplete = View; if (autoComplete == null) { MvxBindingLog.Error( "Error - autoComplete is null in MvxAutoCompleteTextViewPartialTextTargetBinding"); } }
public static bool TargetIsInvalid(object target) { var javaTarget = target as IJavaObject; if (javaTarget != null && javaTarget.Handle == IntPtr.Zero) { MvxBindingLog.Warning("Weak Target has been GCed by Android {0}", javaTarget.GetType().Name); return(true); } return(false); }