private static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var message = sender.GetValue(MessageProperty) as string; var plural_message = sender.GetValue(PluralMessageProperty) as string; var modifier = (StringModifier)sender.GetValue(ModifierProperty); var count = 1; if (message == null) { return; } else if (plural_message != null) { count = (int)sender.GetValue(PluralCountProperty); } var localized = plural_message == null ? Vernacular.Catalog.GetString(message) : Vernacular.Catalog.GetPluralString(message, plural_message, count); localized = ModifyString(localized, modifier); localized = Format(localized, count); var property = FindMessageProperty(sender); if (property != null) { sender.SetValue(property, localized); } #if !XAMARINFORMS else if (sender is Run) { (sender as Run).Text = localized; } #endif }
private static void OnToolTipPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var framework_element = sender as FrameworkElement; if (framework_element == null) { return; } var tooltip = sender.GetValue(ToolTipProperty) as string; if (tooltip == null) { return; } var localized = Vernacular.Catalog.GetString(tooltip); ToolTipService.SetToolTip(framework_element, localized); }
public static Menu GetMenu(BindableObject bindable) { return((Menu)bindable.GetValue(MenuProperty)); }
public static EventsCollection?GetEvents(DependencyObject d) => (EventsCollection?)d.GetValue(EventsProperty);
public static int GetPluralCount(DependencyObject o) { return((int)o.GetValue(PluralCountProperty)); }
public static bool GetSetPaddingInsets(BindableObject obj) => (bool)obj.GetValue(SetPaddingInsetsProperty);
public static View GetTitleView(BindableObject obj) => (View)obj.GetValue(TitleViewProperty);
internal override bool GetState(BindableObject bindable) { return((bool)bindable.GetValue(_stateProperty)); }
public static int GetColumn(BindableObject bindable) { return((int)bindable.GetValue(ColumnProperty)); }
public static Menu GetMenu(BindableObject bindable) => (Menu)bindable.GetValue(MenuProperty);
/// <summary> /// Applies the binding expression to a previously set source or target. /// </summary> void ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget = false) { BindingMode mode = Binding.GetRealizedMode(_targetProperty); if ((mode == BindingMode.OneWay || mode == BindingMode.OneTime) && fromTarget) { return; } bool needsGetter = (mode == BindingMode.TwoWay && !fromTarget) || mode == BindingMode.OneWay || mode == BindingMode.OneTime; bool needsSetter = !needsGetter && ((mode == BindingMode.TwoWay && fromTarget) || mode == BindingMode.OneWayToSource); object current = sourceObject; object previous = null; BindingExpressionPart part = null; for (var i = 0; i < _parts.Count; i++) { part = _parts[i]; bool isLast = i + 1 == _parts.Count; if (!part.IsSelf && current != null) { // Allow the object instance itself to provide its own TypeInfo TypeInfo currentType = current is IReflectableType reflectable?reflectable.GetTypeInfo() : current.GetType().GetTypeInfo(); if (part.LastGetter == null || !part.LastGetter.DeclaringType.GetTypeInfo().IsAssignableFrom(currentType)) { SetupPart(currentType, part); } if (!isLast) { part.TryGetValue(current, out current); } } if (!part.IsSelf && current != null && ((needsGetter && part.LastGetter == null) || (needsSetter && part.NextPart == null && part.LastSetter == null))) { Log.Warning("Binding", PropertyNotFoundErrorMessage, part.Content, current, target.GetType(), property.PropertyName); break; } if (part.NextPart != null && (mode == BindingMode.OneWay || mode == BindingMode.TwoWay) && current is INotifyPropertyChanged inpc) { part.Subscribe(inpc); } previous = current; } Debug.Assert(part != null, "There should always be at least the self part in the expression."); if (needsGetter) { object value = property.DefaultValue; if (part.TryGetValue(current, out value) || part.IsSelf) { value = Binding.GetSourceValue(value, property.ReturnType); } else { value = Binding.FallbackValue ?? property.GetDefaultValue(target); } if (!TryConvert(ref value, property, property.ReturnType, true)) { Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, property.ReturnType); return; } target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted); } else if (needsSetter && part.LastSetter != null && current != null) { object value = Binding.GetTargetValue(target.GetValue(property), part.SetterType); if (!TryConvert(ref value, property, part.SetterType, false)) { Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, part.SetterType); return; } object[] args; if (part.IsIndexer) { args = new object[part.Arguments.Length + 1]; part.Arguments.CopyTo(args, 0); args[args.Length - 1] = value; } else if (part.IsBindablePropertySetter) { args = new[] { part.BindablePropertyField, value }; } else { args = new[] { value }; } part.LastSetter.Invoke(current, args); } }
static bool GetCancelEvents(BindableObject bindable) => (bool)bindable.GetValue(CancelEventsProperty);
public static AbsoluteLayoutFlags GetLayoutFlags(BindableObject bindable) { return((AbsoluteLayoutFlags)bindable.GetValue(LayoutFlagsProperty)); }
public static Rectangle GetLayoutBounds(BindableObject bindable) { return((Rectangle)bindable.GetValue(LayoutBoundsProperty)); }
public static FlyoutBehavior GetFlyoutBehavior(BindableObject obj) => (FlyoutBehavior)obj.GetValue(FlyoutBehaviorProperty);
public static int GetRowSpan(BindableObject bindable) { return((int)bindable.GetValue(RowSpanProperty)); }
public static SearchHandler GetSearchHandler(BindableObject obj) => (SearchHandler)obj.GetValue(SearchHandlerProperty);
public static bool GetIsHeadless(BindableObject bindable) => (bool)bindable.GetValue(IsHeadlessProperty);
public static bool GetTabBarIsVisible(BindableObject obj) => (bool)obj.GetValue(TabBarIsVisibleProperty);
public static Point GetHeadlessOffset(BindableObject bindable) => (Point)bindable.GetValue(HeadlessOffsetProperty);
/// <summary> /// Gets the command from the attached property. /// </summary> /// <param name="dependencyObject">The dependency object to query.</param> /// <returns>The ICommand attached.</returns> public static ICommand GetCommand(DependencyObject dependencyObject) { return(dependencyObject == null ? null : (ICommand)dependencyObject.GetValue(CommandProperty)); }
public static Color GetShellTabBarForegroundColor(BindableObject obj) => (Color)obj.GetValue(ShellTabBarForegroundColorProperty);
public static string GetPluralMessage(DependencyObject o) { return(o.GetValue(PluralMessageProperty) as string); }
public static Color GetShellTitleColor(BindableObject obj) => (Color)obj.GetValue(ShellTitleColorProperty);
public static StringModifier GetModifier(DependencyObject o) { return((StringModifier)o.GetValue(ModifierProperty)); }
public static Color GetShellUnselectedColor(BindableObject obj) => (Color)obj.GetValue(ShellUnselectedColorProperty);
public static string GetToolTip(DependencyObject o) { return((string)o.GetValue(ToolTipProperty)); }
public static BackButtonBehavior GetBackButtonBehavior(BindableObject obj) => (BackButtonBehavior)obj.GetValue(BackButtonBehaviorProperty);
public static string GetComment(DependencyObject o) { return(o.GetValue(CommentProperty) as string); }
internal override bool GetState(BindableObject bindable) { object newValue = bindable.GetValue(_boundProperty); return(EqualsToValue(newValue)); }