public Binding ProvideValue(IServiceProvider serviceProvider) { if (string.IsNullOrWhiteSpace(StringFormat) && Converter == null) { throw new InvalidOperationException($"{nameof(MultiBinding)} requires a {nameof(Converter)} or {nameof(StringFormat)}"); } //Get the object that the markup extension is being applied to var provideValueTarget = (IProvideValueTarget)serviceProvider?.GetService(typeof(IProvideValueTarget)); _target = provideValueTarget?.TargetObject as BindableObject; if (_target == null) { return(null); } foreach (Binding b in Bindings) { var property = BindableProperty.Create($"Property-{Guid.NewGuid().ToString("N")}", typeof(object), typeof(MultiBinding), default(object), propertyChanged: (_, o, n) => SetValue()); _properties.Add(property); _target.SetBinding(property, b); } SetValue(); var binding = new Binding { Path = nameof(InternalValue.Value), Converter = new MultiValueConverterWrapper(Converter, StringFormat), ConverterParameter = ConverterParameter, Source = _internalValue }; return(binding); }
public void EnterAndExitActionsTriggered() { var conditionbp = BindableProperty.Create("foo", typeof(string), typeof(BindableObject), null); var element = new MockElement(); var enteraction = new MockTriggerAction(); var exitaction = new MockTriggerAction(); var trigger = new Trigger(typeof(VisualElement)) { Property = conditionbp, Value = "foobar", EnterActions = { enteraction }, ExitActions = { exitaction } }; Assert.False(enteraction.Invoked); Assert.False(exitaction.Invoked); element.Triggers.Add(trigger); Assert.False(enteraction.Invoked); Assert.False(exitaction.Invoked); element.SetValue(conditionbp, "foobar"); Assert.True(enteraction.Invoked); Assert.False(exitaction.Invoked); enteraction.Invoked = exitaction.Invoked = false; Assert.False(enteraction.Invoked); Assert.False(exitaction.Invoked); element.SetValue(conditionbp, ""); Assert.False(enteraction.Invoked); Assert.True(exitaction.Invoked); }
internal override void Apply(object newContext, BindableObject bindObj, BindableProperty targetProperty) { if (Mode != BindingMode.OneWay) { throw new InvalidOperationException($"{nameof(MultiBinding)} only supports {nameof(Mode)}.{nameof(BindingMode.OneWay)}"); } object source = Context ?? newContext; base.Apply(source, bindObj, targetProperty); _isApplying = true; foreach (BindingBase binding in Bindings) { var property = BindableProperty.Create($"{nameof(MultiBinding)}Property-{Guid.NewGuid().ToString("N")}", typeof(object), typeof(MultiBinding), default(object), propertyChanged: (bindableObj, o, n) => SetValue(bindableObj)); _properties.Add(property); binding.Apply(source, bindObj, property); } _isApplying = false; SetValue(bindObj); _bindingExpression.Apply(_internalValue, bindObj, targetProperty); }
static ItemViewFast() { SelectableProperty = BindableProperty.Create(nameof(SelectableProperty), typeof(bool), typeof(ItemViewFast), false, BindingMode.OneWay, null, (sender, oldVal, newVal) => { if (!(bool)newVal) { ((ItemViewFast)sender).Selected = false; } }); SelectedProperty = BindableProperty.Create(nameof(SelectedProperty), typeof(bool), typeof(ItemViewFast), false, BindingMode.OneWay, null, (sender, oldVal, newVal) => { ((ItemViewFast)sender).BackgroundColor = (bool)newVal ? Controls.Visual.Current.ItemSelection : Controls.Visual.Current.ItemBackground; ((ItemViewFast)sender).RaiseSelectionChanged(); }); StrokeVisibleProperty = BindableProperty.Create(nameof(StrokeVisible), typeof(bool), typeof(ItemViewFast), false, BindingMode.OneWay, null, (sender, oldVal, newVal) => { var itemView = ((ItemViewFast)sender); if ((bool)newVal) { itemView.ShowStroke(); itemView.StartWaitingAndStrokeActions(); } else { itemView.HideStroke(); } }); TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(ItemViewFast), "itemView", BindingMode.OneWay, null, (sender, oldVal, newVal) => { (sender as ItemViewFast).ApplyText(); }); }
public static BindableProperty Create <TDeclarer, TPropertyType>(Expression <Func <TDeclarer, TPropertyType> > getter, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, BindableProperty.ValidateValueDelegate <TPropertyType> validateValue = null, BindableProperty.BindingPropertyChangedDelegate <TPropertyType> propertyChanged = null, BindableProperty.BindingPropertyChangingDelegate <TPropertyType> propertyChanging = null, BindableProperty.CoerceValueDelegate <TPropertyType> coerceValue = null, BindableProperty.CreateDefaultValueDelegate <TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject { return(BindableProperty.Create(ExpressionExtension.GetPropertyPath(getter), typeof(TPropertyType), typeof(TDeclarer), defaultValue, defaultBindingMode, validateValue: (bindable, value) => { return validateValue != null ? validateValue(bindable, (TPropertyType)value) : true; }, propertyChanged: (bindable, oldValue, newValue) => { if (propertyChanged != null) { propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); } }, propertyChanging: (bindable, oldValue, newValue) => { if (propertyChanging != null) { propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); } }, coerceValue: (bindable, value) => { return coerceValue != null ? coerceValue(bindable, (TPropertyType)value) : value; }, defaultValueCreator: (bindable) => { return defaultValueCreator != null ? defaultValueCreator((TDeclarer)bindable) : defaultValue; })); }
public void ClearValueTriggersINPC() { var bindable = new MockBindable(); bool changingfired = false; bool changedfired = false; bool changingdelegatefired = false; bool changeddelegatefired = false; var property = BindableProperty.Create("Foo", typeof(string), typeof(MockBindable), "foo", propertyChanged: (b, o, n) => changeddelegatefired = true, propertyChanging: (b, o, n) => changingdelegatefired = true ); bindable.PropertyChanged += (sender, e) => { changedfired |= e.PropertyName == "Foo"; }; bindable.PropertyChanging += (sender, e) => { changingfired |= e.PropertyName == "Foo"; }; bindable.SetValue(property, "foobar"); changingfired = changedfired = changeddelegatefired = changingdelegatefired = false; bindable.ClearValue(property); Assert.True(changingfired); Assert.True(changedfired); Assert.True(changingdelegatefired); Assert.True(changeddelegatefired); }
public FreteEmpresaCell() { inicializarComponente(); _Nota = BindableProperty.Create("_Nota", typeof(int), typeof(FreteEmpresaCell), default(int)); this.SetBinding(_Nota, new Binding("NotaFrete")); _IdFrete = BindableProperty.Create("_IdFrete", typeof(int), typeof(FreteEmpresaCell), default(int)); this.SetBinding(_IdFrete, new Binding("Id")); View = new StackLayout { Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Margin = 10, Children = { _StatusLabel, _OrigemDestinoLabel, _Caminhoneiro, _DataCriacao, _DataRetirada, _DataConclusao, _Fretista, _ContatoFretista, _VerHistorico, _Definicao, _Carga, _Valor, _Avaliar, _AvaliacaoTitulo, _AvaliacaoView, _Editar } }; }
public void ValueUpdatedWithSimplePathOnOneWayBinding( [Values(true, false)] bool isDefault) { const string newvalue = "New Value"; var viewmodel = new MockViewModel { Text = "Foo" }; BindingMode propertyDefault = BindingMode.OneWay; BindingMode bindingMode = BindingMode.OneWay; if (isDefault) { propertyDefault = BindingMode.OneWay; bindingMode = BindingMode.Default; } var property = BindableProperty.Create("Text", typeof(string), typeof(MockBindable), "default value", propertyDefault); var binding = CreateBinding(bindingMode); var bindable = new MockBindable(); bindable.BindingContext = viewmodel; bindable.SetBinding(property, binding); viewmodel.Text = newvalue; Assert.AreEqual(newvalue, bindable.GetValue(property), "Bindable did not update on binding context property change"); Assert.AreEqual(newvalue, viewmodel.Text, "Source property changed when it shouldn't"); var messages = MockApplication.MockLogger.Messages; Assert.That(messages.Count, Is.EqualTo(0), "An error was logged: " + messages.FirstOrDefault()); }
/// <summary> /// 静态构造器 /// </summary> static Node() { //注册依赖属性 IsSelectedProperty = BindableProperty.Create("IsSelected", typeof(bool?), typeof(Node), null, BindingMode.TwoWay); IsCheckedProperty = BindableProperty.Create("IsChecked", typeof(bool?), typeof(Node), null, BindingMode.TwoWay, null, OnIsCheckedChanged); }
public static BindableProperty CreateProperty <T>(string propertyName, T defaultValue = default, BindingMode mode = BindingMode.TwoWay) { return(BindableProperty.Create(propertyName, typeof(T), typeof(BindableObject), defaultValue, mode)); }
public CardView() { CardViewHorizontalOptionsProperty = BindableProperty.Create( propertyName: "CardViewHorizontalOptions", returnType: typeof(LayoutOptions), declaringType: typeof(CardView), defaultValue: LayoutOptions.Start, propertyChanged: CardViewHorizontalOptionsChanged); CardViewContentProperty = BindableProperty.Create( propertyName: "CardViewContent", returnType: typeof(View), declaringType: typeof(CardView), propertyChanged: CardViewContentChanged); CardViewOutlineColorThicknessProperty = BindableProperty.Create( propertyName: "CardViewOutlineColorThickness", returnType: typeof(Thickness), declaringType: typeof(CardView), defaultValue: new Thickness(0), propertyChanged: CardViewOutlineColorThicknessChanged); CardViewHeightRequestProperty = BindableProperty.Create( propertyName: "CardViewHeightRequest", returnType: typeof(double), declaringType: typeof(CardView), defaultValue: -1d, propertyChanged: CardViewHeightRequestChanged); CardViewOutlineColorThicknessProperty = BindableProperty.Create( propertyName: "CardViewOutlineColorThickness", returnType: typeof(Thickness), declaringType: typeof(CardView), defaultValue: new Thickness(0), propertyChanged: CardViewOutlineColorThicknessChanged); CardViewInnerFrameOutlineColorProperty = BindableProperty.Create( propertyName: "CardViewInnerFrameOutlineColor", declaringType: typeof(CardView), returnType: typeof(Color), defaultValue: Color.Transparent, propertyChanged: CardViewInnerFrameOutlineColorChanged); CardViewOutlineColorProperty = BindableProperty.Create( propertyName: "CardViewOutlineColor", declaringType: typeof(CardView), returnType: typeof(Color), defaultValue: Color.Transparent, propertyChanged: CardViewOutlineColorChanged); CardViewInnerFrameOutlineColorThicknessProperty = BindableProperty.Create( propertyName: "CardViewInnerFrameOutlineColorThickness", returnType: typeof(Thickness), declaringType: typeof(CardView), defaultValue: new Thickness(0), propertyChanged: CardViewInnerFrameOutlineColorThicknessChanged); CardViewHasShadowProperty = BindableProperty.Create( propertyName: "CardViewHasShadow", returnType: typeof(bool), declaringType: typeof(CardView), defaultValue: false, propertyChanged: CardViewHasShadowChanged); IsSwipeToClearEnabledProperty = BindableProperty.Create( propertyName: "IsSwipeToClearEnabled", returnType: typeof(bool), declaringType: typeof(CardView), defaultValue: false, propertyChanged: CardViewSwipeToClearPropertyChanged); _innerFrame = new Frame { Padding = CardViewInnerFrameOutlineColorThickness, HasShadow = false, OutlineColor = Color.Transparent, BackgroundColor = CardViewInnerFrameOutlineColor, HeightRequest = CardViewHeightRequest, HorizontalOptions = CardViewHorizontalOptions }; _outerFrame = new Frame { Padding = CardViewOutlineColorThickness, HasShadow = CardViewHasShadow, OutlineColor = Color.Transparent, HeightRequest = CardViewHeightRequest, BackgroundColor = CardViewOutlineColor }; _outerFrame.Content = _innerFrame; Content = _outerFrame; }
public void SetMyValue(this Page page, out BindableProperty headerTextProperty, string value) { headerTextProperty = null; headerTextProperty = BindableProperty.Create("HeaderText", typeof(string), typeof(SearchPage), value); page.OnPropertyChanged("HeaderText"); }
static SignaturePadView() { StrokeColorProperty = BindableProperty.Create( nameof(StrokeColor), typeof(Color), typeof(SignaturePadView), ImageConstructionSettings.DefaultStrokeColor, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).SignaturePadCanvas.StrokeColor = (Color)newValue); StrokeWidthProperty = BindableProperty.Create( nameof(StrokeWidth), typeof(float), typeof(SignaturePadView), ImageConstructionSettings.DefaultStrokeWidth, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).SignaturePadCanvas.StrokeWidth = (float)newValue); SignatureLineColorProperty = BindableProperty.Create( nameof(SignatureLineColor), typeof(Color), typeof(SignaturePadView), SignaturePadDarkColor, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).SignatureLine.Color = (Color)newValue); SignatureLineWidthProperty = BindableProperty.Create( nameof(SignatureLineWidth), typeof(double), typeof(SignaturePadView), DefaultLineWidth, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).SignatureLine.HeightRequest = (double)newValue); SignatureLineSpacingProperty = BindableProperty.Create( nameof(SignatureLineSpacing), typeof(double), typeof(SignaturePadView), DefaultNarrowSpacing, propertyChanged: OnPaddingChanged); CaptionTextProperty = BindableProperty.Create( nameof(CaptionText), typeof(string), typeof(SignaturePadView), DefaultCaptionText, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).CaptionLabel.Text = (string)newValue); CaptionFontSizeProperty = BindableProperty.Create( nameof(CaptionFontSize), typeof(double), typeof(SignaturePadView), DefaultFontSize, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).CaptionLabel.FontSize = (double)newValue); CaptionTextColorProperty = BindableProperty.Create( nameof(CaptionTextColor), typeof(Color), typeof(SignaturePadView), SignaturePadDarkColor, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).CaptionLabel.TextColor = (Color)newValue); PromptTextProperty = BindableProperty.Create( nameof(PromptText), typeof(string), typeof(SignaturePadView), DefaultPromptText, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).SignaturePrompt.Text = (string)newValue); PromptFontSizeProperty = BindableProperty.Create( nameof(PromptFontSize), typeof(double), typeof(SignaturePadView), DefaultFontSize, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).SignaturePrompt.FontSize = (double)newValue); PromptTextColorProperty = BindableProperty.Create( nameof(PromptTextColor), typeof(Color), typeof(SignaturePadView), SignaturePadDarkColor, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).SignaturePrompt.TextColor = (Color)newValue); ClearTextProperty = BindableProperty.Create( nameof(ClearText), typeof(string), typeof(SignaturePadView), DefaultClearLabelText, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).ClearLabel.Text = (string)newValue); ClearFontSizeProperty = BindableProperty.Create( nameof(ClearFontSize), typeof(double), typeof(SignaturePadView), DefaultFontSize, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).ClearLabel.FontSize = (double)newValue); ClearTextColorProperty = BindableProperty.Create( nameof(ClearTextColor), typeof(Color), typeof(SignaturePadView), SignaturePadDarkColor, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).ClearLabel.TextColor = (Color)newValue); BackgroundImageProperty = BindableProperty.Create( nameof(BackgroundImage), typeof(ImageSource), typeof(SignaturePadView), default(ImageSource), propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).BackgroundImageView.Source = (ImageSource)newValue); BackgroundImageAspectProperty = BindableProperty.Create( nameof(BackgroundImageAspect), typeof(Aspect), typeof(SignaturePadView), Aspect.AspectFit, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).BackgroundImageView.Aspect = (Aspect)newValue); BackgroundImageOpacityProperty = BindableProperty.Create( nameof(BackgroundImageOpacity), typeof(double), typeof(SignaturePadView), 1.0, propertyChanged: (bindable, oldValue, newValue) => ((SignaturePadView)bindable).BackgroundImageView.Opacity = (double)newValue); ClearedCommandProperty = BindableProperty.Create( nameof(ClearedCommand), typeof(ICommand), typeof(SignaturePadView), default(ICommand)); StrokeCompletedCommandProperty = BindableProperty.Create( nameof(StrokeCompletedCommand), typeof(ICommand), typeof(SignaturePadView), default(ICommand)); IsBlankPropertyKey = BindableProperty.CreateReadOnly( nameof(IsBlank), typeof(bool), typeof(SignaturePadView), true); IsBlankProperty = IsBlankPropertyKey.BindableProperty; }
static GridElement() { BorderColorProperty = BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(GridElement), Color.FromHex("A4CAEC"), BindingMode.OneWay); SymbolProperty = BindableProperty.Create(nameof(Symbol), typeof(string), typeof(GridElement), "Sy", BindingMode.OneWay); }
/// <summary> /// Initializes static members of the <see cref="HyperLinkLabel"/> class. /// </summary> static HyperLinkLabel() { SubjectProperty = BindableProperty.Create("Subject", typeof(string), typeof(HyperLinkLabel), string.Empty, BindingMode.OneWay, null, null, null, null); NavigateUriProperty = BindableProperty.Create("NavigateUri", typeof(string), typeof(HyperLinkLabel), string.Empty, BindingMode.OneWay, null, null, null, null); }
static HyperLinkControl() { NavigateUriProperty = BindableProperty.Create("NavigateUri", typeof(string), typeof(HyperLinkControl), string.Empty); }
static StarCell() { FlagsProperty = BindableProperty.Create <StarCell> ((StarCell c) => c.Flags, (byte)0, BindingMode.OneWay, null, null, null, null); }