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 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; } } }
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; } }
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."); } }
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); }
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 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 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); } }
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); } } }
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()); } }
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 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 MvxUIButtonTitleTargetBinding(UIButton button, UIControlState state = UIControlState.Normal) : base(button) { _state = state; if (button == null) { MvxBindingLog.Error("Error - UIButton is null in MvxUIButtonTitleTargetBinding"); } }
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 MvxTextViewTextTargetBinding(TextView target) : base(target) { if (target == null) { MvxBindingLog.Error("Error - TextView is null in MvxTextViewTextTargetBinding"); return; } _isEditTextBinding = target is EditText; }
public override void SubscribeToEvents() { var segmentedControl = View; if (segmentedControl == null) { MvxBindingLog.Error("Error - UISegmentedControl is null in MvxUISegmentedControlSelectedSegmentTargetBinding"); return; } _subscription = segmentedControl.WeakSubscribe(nameof(segmentedControl.ValueChanged), HandleValueChanged); }
public override void SubscribeToEvents() { var uiSwitch = Target; if (uiSwitch == null) { MvxBindingLog.Error("Error - Switch is null in MvxUISwitchOnTargetBinding"); return; } _subscription = uiSwitch.WeakSubscribe(nameof(uiSwitch.ValueChanged), HandleValueChanged); }
public IMvxTargetBinding CreateBinding(object target, string targetName) { var castTarget = target as TTarget; if (castTarget == null) { MvxBindingLog.Error("Passed an invalid target for MvxCustomBindingFactory"); return(null); } return(_targetBindingCreator(castTarget)); }
public override void SubscribeToEvents() { var slider = View; if (slider == null) { MvxBindingLog.Error("Error - UISlider is null in MvxUISliderValueTargetBinding"); return; } _subscription = slider.WeakSubscribe(nameof(slider.ValueChanged), HandleSliderValueChanged); }
public override void SubscribeToEvents() { var pageControl = View; if (pageControl == null) { MvxBindingLog.Error("UIPageControl is null in MvxUIPageControlCurrentPageTargetBinding"); return; } _subscription = pageControl.WeakSubscribe(nameof(pageControl.ValueChanged), HandleValueChanged); }
private static object SafeGetFieldValue(Type styleable, string fieldName, object defaultValue) { var field = styleable.GetField(fieldName); if (field == null) { MvxBindingLog.Error("Missing stylable field {0}", fieldName); return(defaultValue); } return(field.GetValue(null)); }
public override void SubscribeToEvents() { var searchBar = View; if (searchBar == null) { MvxBindingLog.Error( "Error - UISearchBar is null in MvxUISearchBarTextTargetBinding"); return; } _subscription = searchBar.WeakSubscribe <UISearchBar, UISearchBarTextChangedEventArgs>(nameof(searchBar.TextChanged), HandleSearchBarValueChanged); }
public override void SubscribeToEvents() { var segmentedControl = View; if (segmentedControl == null) { MvxBindingLog.Error("Error - NSSegmentedControl is null in MvxNSSegmentedControlSelectedSegmentTargetBinding"); return; } _subscribed = true; segmentedControl.Activated += HandleValueChanged; }
public MvxUIBarButtonItemTargetBinding(UIBarButtonItem control) : base(control) { if (control == null) { MvxBindingLog.Error("Error - UIControl is null in MvxUIBarButtonItemTargetBinding"); } else { _clickSubscription = control.WeakSubscribe(nameof(control.Clicked), OnClicked); } _canExecuteEventHandler = OnCanExecuteChanged; }
public override void SubscribeToEvents() { var myView = View; if (myView == null) { MvxBindingLog.Error($"Error - MyView is null in {nameof(MvxListViewItemClickPropertyTargetBinding)}"); return; } _subscribed = true; myView.ItemTapped += HandleMyPropertyChanged; }