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 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;
        }
		protected override DataTemplate OnSelectTemplate(object item, int columnIndex, BindableObject container)
		{
			if (columnIndex == 0)
				return _leftTemplate;

			return _rightTemplate;
		}
 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 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());
 }
        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;
            }
        }
Example #7
0
		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 });
		}
Example #8
0
			public MergedStyle(Type targetType, BindableObject target)
			{
				Target = target;
				TargetType = targetType;
				RegisterImplicitStyles();
				Apply(Target);
			}
//		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());
					}
				}
			}
		}
Example #10
0
        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 ApplyStyle(BindableObject bindable, Style newvalue)
 {
   foreach (var setter in newvalue.Setters )
   {
       bindable.SetValue(setter.Property, setter.Value);
   }
 }
		/// <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;
		}
        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++;
            }
        }
 public static Android.Views.View GetNativeView(BindableObject bindableObject)
 {
     var renderer = bindableObject.GetRenderer ();
     var viewGroup = renderer.ViewGroup;
     var rootView = viewGroup.RootView;
     return rootView;
 }
Example #15
0
		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;
		}
Example #16
0
		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 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;
        }
Example #18
0
        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 ();
            }
        }
        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();
        }
 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++;
         }
     }
 }
        /// <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 ());
        }
		static void OnContentChanged( BindableObject bindable, object oldvalue, object newvalue )
		{
			var view = bindable as ContentView;
			if ( view != null )
			{
				view.Content = newvalue as View;
			}
		}
Example #24
0
		void OnAggregatedStatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
		{
			if ((bool)oldValue == (bool)newValue)
				return;

			if (ConditionChanged != null)
				ConditionChanged(bindable, (bool)oldValue, (bool)newValue);
		}
        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;
        }
Example #26
0
		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;
		}
 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());
     }
 }
 /// <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;
 }
Example #29
0
			public void Apply(BindableObject bindable)
			{
				ImplicitStyle?.Apply(bindable);
				if (ClassStyles != null)
					foreach (var classStyle in ClassStyles)
						((IStyle)classStyle)?.Apply(bindable);
				Style?.Apply(bindable);
			}
			protected override DataTemplate OnSelectTemplate (object item, BindableObject container)
			{
				if (item is double)
					return templateOne;
				if (item is byte)
					return new TestDTS ();
				return templateTwo;
			}