private static void ItemsSourceChanged(BindableObject bindable, IEnumerable oldValue, IEnumerable newValue) { var picker = (Picker)bindable; if (picker == null) throw new Exception("only support Picker"); var selected = picker.SelectedIndex; var type = newValue.GetType().GenericTypeArguments[0].GetTypeInfo(); var dp = (string)bindable.GetValue(DisplayPathProperty); PropertyInfo p = null; if (!string.IsNullOrWhiteSpace(dp)) { p = type.GetDeclaredProperty(dp); } foreach (var o in newValue) { object value = null; if (p != null) value = p.GetValue(o); else value = o; if (value != null) picker.Items.Add(value.ToString()); } picker.SelectedIndex = selected; }
private static void ItemsSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue) { var articles = newValue as IEnumerable; var galery = bindable as ArticleCarouselView; if (galery != null) { if (articles != null) { foreach (var article in articles) { try { galery.BatchBegin(); galery.Children.Add(new BigArticleView {BindingContext = article}); galery.BatchCommit(); } catch { } } } else { try { galery.Children.Clear(); } catch { } } } }
private static void OnItemsSourceChanged(BindableObject bindable, IEnumerable oldvalue, IEnumerable newvalue) { var radButtons = bindable as BindableRadioGroup; radButtons.rads.Clear(); radButtons.Children.Clear(); if (newvalue != null) { int radIndex = 0; foreach (var item in newvalue) { var rad = new CustomRadioButton(); rad.Text = item.ToString(); rad.Id = radIndex; rad.CheckedChanged += radButtons.OnCheckedChanged; radButtons.rads.Add(rad); radButtons.Children.Add(rad); radIndex++; } } }
private static void VMChanged(BindableObject bindable, object oldValue, object newValue) { if (newValue == null) return; var vm = (Screen)newValue; //var view = vm.GetView(); var vmView = ViewLocator.LocateForModel(vm, null, null); if (vmView == null) throw new Exception("没有找到视图"); ViewModelBinder.Bind(vm, vmView, null); var activator = vm as IActivate; if (activator != null) activator.Activate(); var page = (ViewLocatorPage)bindable; if (null != (ContentPage)vmView) { var vp = (ContentPage)vmView; page.Content = vp.Content; if (vp.ToolbarItems != null) foreach (var t in vp.ToolbarItems) page.ToolbarItems.Add(t); } else if (null != (Xamarin.Forms.View)vmView) { page.Content = (Xamarin.Forms.View)vmView; } }
// void UpdateSelected() // { // if (ItemsSource != null) // { // if (ItemsSource.Contains(SelectedItem)) // { // SelectedIndex = ItemsSource.IndexOf(SelectedItem); // } // else // { // SelectedIndex = -1; // } // } // } static void OnItemsSourceChanged(BindableObject bindable, IList oldvalue, IList newvalue) { var picker = bindable as BindablePicker; if (picker != null) { picker.Items.Clear(); if (newvalue == null) return; //now it works like "subscribe once" but you can improve foreach (var item in newvalue) { if (string.IsNullOrEmpty(picker.DisplayMember)) { picker.Items.Add(item.ToString()); } else { var type = item.GetType(); var prop = type.GetProperty(picker.DisplayMember); picker.Items.Add(prop.GetValue(item).ToString()); } } } }
private static void CommandParameterPropertyChanged(BindableObject bindable, object oldvalue, object newvalue) { var gesture = ((ExtendedImage) bindable)._tapGestureRecognizer; if (gesture != null && gesture.Command != null) ((RelayCommand)gesture.Command).RaiseCanExecuteChanged(); }
private static void ApplyStyle(BindableObject bindable, Style newvalue) { foreach (var setter in newvalue.Setters ) { bindable.SetValue(setter.Property, setter.Value); } }
private static void OnItemsSourceChanged(BindableObject bindable, IEnumerable oldvalue, IEnumerable newvalue) { var radios = bindable as BindableRadioButtonGroup; if (radios == null) { return; } radios.RadioButtons.Clear(); radios.Children.Clear(); if (newvalue == null) { return; } var index = 0; foreach (var item in newvalue) { var radioButton = new CustomRadioButton { Text = item.ToString(), Id = index }; radioButton.CheckedChanged += radios.OnCheckedChanged; radios.RadioButtons.Add(radioButton); radios.Children.Add(radioButton); index++; } }
protected override DataTemplate OnSelectTemplate(object item, int columnIndex, BindableObject container) { if (columnIndex == 0) return _leftTemplate; return _rightTemplate; }
private static void OnItemsSourcePropertyChanged(BindableObject bindable, IEnumerable<ILabel> oldvalue, IEnumerable<ILabel> newvalue) { var control = bindable as Label; control.FormattedText = null; if (newvalue == null) return; var formattedString = new FormattedString(); foreach (var label in newvalue) { var color = Color.FromHex(label.Color); formattedString.Spans.Add(new Span { Text = $"\u00A0{label.Name}\u00A0", ForegroundColor = (Color) Application.Current.Resources[ (color.Hue > 0 ? "PrimaryLightTextColor" : "PrimaryDarkTextColor")], BackgroundColor = color }); formattedString.Spans.Add(new Span { Text = " " }); } control.FormattedText = formattedString; }
static void UpdateTexts(BindableObject bindable, string oldValue, string newValue) { var instance = bindable as Bz29300DummyView; instance.Children.Clear(); for (int i = 0; i < instance.NumOfRepeat; i++) instance.Children.Add(new Label() {Text = newValue }); }
/// <summary> /// Creates an instance of the GridDefinitionBindingHack class. /// </summary> private GridDefinitionBindingHelper(GridSplitter s, BindableObject o, BindableProperty p, BindableProperty p2) { // preconditions Argument.IsNotNull("s", s); Argument.IsNotNull("o", o); Argument.IsNotNull("p", p); // implementation this.splitter = s; this.bindableObject = o; this.sizeProperty = p; this.visibleProperty = p2; // update the property if the column width/row height changes. s.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e) { this.AdjustPropertyValue(); }; // update the column width/row height if the property value changes. o.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == this.sizeProperty.Name || (this.visibleProperty != null && e.PropertyName == this.visibleProperty.Name)) { this.AdjustDefinationValue(); } }; }
/// <summary> /// Called when [items source property changed]. /// </summary> /// <param name="bindable">The bindable.</param> /// <param name="value">The value.</param> /// <param name="newValue">The new value.</param> private static void OnItemsSourcePropertyChanged(BindableObject bindable, IEnumerable value, IEnumerable newValue) { var picker = (BindablePicker)bindable; var notifyCollection = newValue as INotifyCollectionChanged; if (notifyCollection != null) { notifyCollection.CollectionChanged += (sender, args) => { if (args.NewItems != null) { foreach (var newItem in args.NewItems) { picker.Items.Add ((newItem ?? "").ToString ()); } } if (args.OldItems != null) { foreach (var oldItem in args.OldItems) { picker.Items.Remove ((oldItem ?? "").ToString ()); } } }; } if (newValue == null) return; picker.Items.Clear (); foreach (var item in newValue) picker.Items.Add ((item ?? "").ToString ()); }
public MergedStyle(Type targetType, BindableObject target) { Target = target; TargetType = targetType; RegisterImplicitStyles(); Apply(Target); }
private static void IsShowAnimChanged(BindableObject bindable, bool oldvalue, bool newvalue) { var control = bindable as SkypeAnimControl; if(control == null) return; control.IsShowAnim = newvalue; control.ShowAnimEvent?.Invoke(control, new EventArgs()); }
static void OnHorizontalTextAlignmentPropertyChanged(BindableObject bindable, object oldValue, object newValue) { var label = (EntryCell)bindable; #pragma warning disable 0618 // retain until XAlign removed label.OnPropertyChanged(nameof(XAlign)); #pragma warning restore }
private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue) { BoundPicker boundPicker = (BoundPicker)bindable; //boundPicker.BatchBegin (); try { boundPicker.Items.Clear(); var enumerable = newValue as IEnumerable; if (enumerable != null && enumerable.GetEnumerator().MoveNext()) { foreach (var item in enumerable) { boundPicker.Items.Add(item.ToString()); } } else { boundPicker.Items.Add(" "); } boundPicker.InternalUpdateSelectedIndex(); } finally { //boundPicker.BatchCommit (); } }
public static Android.Views.View GetNativeView(BindableObject bindableObject) { var renderer = bindableObject.GetRenderer (); var viewGroup = renderer.ViewGroup; var rootView = viewGroup.RootView; return rootView; }
private static void OnIsSelectedChanged (BindableObject bindable, object oldvalue, object newvalue) { var tabButton = bindable as TabButton; tabButton.BackgroundColor = tabButton.IsSelected ? AppConstants.HeaderBackground : Color.Transparent; tabButton.TextColor = tabButton.IsSelected ? AppConstants.HeaderTextColour : AppConstants.TextColour; }
/// <summary> /// Selects the template. /// </summary> /// <returns>The template.</returns> /// <param name="item">Item.</param> /// <param name="columnIndex">Column index.</param> /// <param name="container">Container.</param> public DataTemplate SelectTemplate(object item, int columnIndex, BindableObject container) { DataTemplate result = OnSelectTemplate(item, columnIndex, container); if (result is DataTemplateSelector || result is FlowTemplateSelector) throw new NotSupportedException("FlowTemplateSelector.OnSelectTemplate must not return another DataTemplateSelector"); return result; }
static void loadItemsAndSetSelected(BindableObject bindable) { ExtendedPicker picker = (ExtendedPicker)bindable; if (picker.ItemsSource as IEnumerable != null) { int count = 0; foreach (object obj in (IEnumerable)picker.ItemsSource) { string value = string.Empty; if (picker.DisplayProperty != null) { var prop = obj.GetType().GetRuntimeProperties().FirstOrDefault(p => string.Equals(p.Name, picker.DisplayProperty, StringComparison.OrdinalIgnoreCase)); if (prop != null) { value = prop.GetValue(obj).ToString(); } } else { value = obj.ToString(); } picker.Items.Add(value); if (picker.SelectedItem != null) { if (picker.SelectedItem == obj) { picker.SelectedIndex = count; } } count++; } } }
private static void AccessoryButtonsPropertyChanging(BindableObject bindable, object oldvalue, object newvalue) { var oldList = oldvalue as List<ToolBarButton>; if (oldList != null) { foreach (var button in oldList) button.BindingContext = null; } var oldObs = oldvalue as INotifyCollectionChanged; if (oldObs != null) oldObs.CollectionChanged -= ((ToolBar)bindable).ButtonsOnCollectionChanged; var newList = newvalue as List<ToolBarButton>; if (newList != null) { var entry = (ExtendedEntry)bindable; foreach (var button in newList) button.BindingContext = entry.BindingContext; } var newObs = newvalue as INotifyCollectionChanged; if (newObs != null) newObs.CollectionChanged += ((ToolBar)bindable).ButtonsOnCollectionChanged; }
private static void OnSelectedItemChanged(BindableObject bindable, object oldvalue, object newvalue) { var picker = bindable as BindablePicker; if (newvalue != null) { picker.SelectedIndex = picker.Items.IndexOf(newvalue.ToString()); } }
static void OnContentChanged( BindableObject bindable, object oldvalue, object newvalue ) { var view = bindable as ContentView; if ( view != null ) { view.Content = newvalue as View; } }
/// <summary> /// Clears the cache when the set of templates change /// </summary> /// <param name="bo"></param> /// <param name="oldval"></param> /// <param name="newval"></param> public static void TemplatesChanged(BindableObject bo, DataTemplateCollection oldval, DataTemplateCollection newval) { var ts = bo as TemplateSelector; if (ts == null) return; if (oldval != null) oldval.CollectionChanged -= ts.TemplateSetChanged; newval.CollectionChanged += ts.TemplateSetChanged; ts.Cache = null; }
internal override void SetUp(BindableObject bindable) { object newvalue = bindable.GetValue(Property); bool newState = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value)); bindable.SetValue(_stateProperty, newState); bindable.PropertyChanged += OnAttachedObjectPropertyChanged; }
protected override DataTemplate OnSelectTemplate (object item, BindableObject container) { if (item is double) return templateOne; if (item is byte) return new TestDTS (); return templateTwo; }
public void Apply(BindableObject bindable) { ImplicitStyle?.Apply(bindable); if (ClassStyles != null) foreach (var classStyle in ClassStyles) ((IStyle)classStyle)?.Apply(bindable); Style?.Apply(bindable); }
private static void OnImageSourceChanged(BindableObject bindable, string oldvalue, string newvalue) { if (Device.OS == TargetPlatform.Android) return; var image = (XLargeImage)bindable; var baseImage = (Image)bindable; baseImage.Source = image.ImageSource; }
void OnAggregatedStatePropertyChanged(BindableObject bindable, object oldValue, object newValue) { if ((bool)oldValue == (bool)newValue) return; if (ConditionChanged != null) ConditionChanged(bindable, (bool)oldValue, (bool)newValue); }
public static void SetVerifyNumericValue(BindableObject view, bool value) { view.SetValue(VerifyNumericValueProperty, value); }
private static void OnCollectionChangedListenerChanging(BindableObject bindable, object oldValue, object newValue) { (oldValue as CollectionChangedListener)?.Dispose(); }
internal static void SetRaiseCanExecuteChangedInternal(BindableObject view, Action value) => view.SetValue(RaiseCanExecuteChangedInternalProperty, value);
/// <summary> /// Gets the Bindable Can Navigate property for an element /// </summary> /// <param name="view">The bindable element</param> public static bool GetCanNavigate(BindableObject view) => (bool)view.GetValue(CanNavigateProperty);
public static DataTemplate GetItemTemplate(BindableObject bindable) => (DataTemplate)bindable.GetValue(ItemTemplateProperty);
private static CollectionChangedListener GetCollectionChangedListener(BindableObject bindable) => (CollectionChangedListener)bindable.GetValue(CollectionChangedListenerProperty);
public static bool GetUseSafeArea(BindableObject element) { return((bool)element.GetValue(UseSafeAreaProperty)); }
public static LargeTitleDisplayMode GetLargeTitleDisplay(BindableObject element) { return((LargeTitleDisplayMode)element.GetValue(LargeTitleDisplayProperty)); }
public static void SetCornerRadius(BindableObject view, int value) => view.SetValue(CornerRadiusProperty, value);
public static void IsIndicatorRunningChanged(BindableObject bindableObject, object oldValue, object newValue) => (bindableObject as LoadingButtonControl).IsIndicatorRunning = (bool)newValue;
public static void ClickCommandChanged(BindableObject bindableObject, object oldValue, object newValue) => (bindableObject as LoadingButtonControl).ClickCommand = (Command)newValue;
/// <summary> /// Sets the Bindable Can Navigate property for an element /// </summary> /// <param name="view">The bindable element</param> /// <param name="value">The Can Navigate value</param> public static void SetCanNavigate(BindableObject view, bool value) => view.SetValue(CanNavigateProperty, value);
private static void SetCollectionChangedListener(BindableObject bindable, CollectionChangedListener value) => bindable.SetValue(CollectionChangedListenerProperty, value);
/// <summary> /// Convenience helper, which enables you to bind any property /// of your View Model to an object you pass in. /// </summary> protected void BindToViewModel(BindableObject self, BindableProperty targetProperty, Expression <Func <TViewModel, object> > sourceProperty, BindingMode mode = BindingMode.Default, IValueConverter converter = null, string stringFormat = null) { self.SetBinding(targetProperty, sourceProperty, mode, converter, stringFormat); }
public static void SetSeparatorTemplate(BindableObject bindable, DataTemplate value) => bindable.SetValue(SeparatorTemplateProperty, value);
public static int GetCornerRadius(BindableObject view) => (int)view.GetValue(CornerRadiusProperty);
public static DataTemplate GetSeparatorTemplate(BindableObject bindable) => (DataTemplate)bindable.GetValue(SeparatorTemplateProperty);
public static void SetItemsSource(BindableObject bindable, IEnumerable value) => bindable.SetValue(ItemsSourceProperty, value);
public static void SetItemTemplate(BindableObject bindable, DataTemplate value) => bindable.SetValue(ItemTemplateProperty, value);
public static void SetLargeTitleDisplay(BindableObject element, LargeTitleDisplayMode value) { element.SetValue(LargeTitleDisplayProperty, value); }
internal static void SetRealCell(BindableObject cell, UITableViewCell renderer) { cell.SetValue(RealCellProperty, renderer); }
private static void OnCanNavigatePropertyChanged(BindableObject bindable, object oldvalue, object newvalue) { var action = GetRaiseCanExecuteChangedInternal(bindable); action?.Invoke(); }
public static IEnumerable GetItemsSource(BindableObject bindable) => (IEnumerable)bindable.GetValue(ItemsSourceProperty);
internal static UITableViewCell GetRealCell(BindableObject cell) { return((UITableViewCell)cell.GetValue(RealCellProperty)); }
public static void SetUseSafeArea(BindableObject element, bool value) { element.SetValue(UseSafeAreaProperty, value); }
internal static Action GetRaiseCanExecuteChangedInternal(BindableObject view) => (Action)view.GetValue(RaiseCanExecuteChangedInternalProperty);
public static void SetAppearing(BindableObject bindable, bool value) { bindable.SetValue(AppearingProperty, value); }
public static bool GetVerifyNumericValue(BindableObject view) { return((bool)view.GetValue(VerifyNumericValueProperty)); }
public static bool GetAppearing(BindableObject bindable) { return((bool)bindable.GetValue(AppearingProperty)); }
public static UIStatusBarAnimation GetPreferredStatusBarUpdateAnimation(BindableObject element) { return((UIStatusBarAnimation)element.GetValue(PreferredStatusBarUpdateAnimationProperty)); }