示例#1
0
        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
        }
示例#2
0
        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);
        }
示例#3
0
 public static Menu GetMenu(BindableObject bindable)
 {
     return((Menu)bindable.GetValue(MenuProperty));
 }
示例#4
0
 public static EventsCollection?GetEvents(DependencyObject d) =>
 (EventsCollection?)d.GetValue(EventsProperty);
示例#5
0
 public static int GetPluralCount(DependencyObject o)
 {
     return((int)o.GetValue(PluralCountProperty));
 }
示例#6
0
 public static bool GetSetPaddingInsets(BindableObject obj) => (bool)obj.GetValue(SetPaddingInsetsProperty);
示例#7
0
 public static View GetTitleView(BindableObject obj) => (View)obj.GetValue(TitleViewProperty);
示例#8
0
 internal override bool GetState(BindableObject bindable)
 {
     return((bool)bindable.GetValue(_stateProperty));
 }
示例#9
0
 public static int GetColumn(BindableObject bindable)
 {
     return((int)bindable.GetValue(ColumnProperty));
 }
示例#10
0
 public static Menu GetMenu(BindableObject bindable) => (Menu)bindable.GetValue(MenuProperty);
示例#11
0
        /// <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);
            }
        }
示例#12
0
 static bool GetCancelEvents(BindableObject bindable) => (bool)bindable.GetValue(CancelEventsProperty);
示例#13
0
 public static AbsoluteLayoutFlags GetLayoutFlags(BindableObject bindable)
 {
     return((AbsoluteLayoutFlags)bindable.GetValue(LayoutFlagsProperty));
 }
示例#14
0
 public static Rectangle GetLayoutBounds(BindableObject bindable)
 {
     return((Rectangle)bindable.GetValue(LayoutBoundsProperty));
 }
示例#15
0
 public static FlyoutBehavior GetFlyoutBehavior(BindableObject obj) => (FlyoutBehavior)obj.GetValue(FlyoutBehaviorProperty);
示例#16
0
 public static int GetRowSpan(BindableObject bindable)
 {
     return((int)bindable.GetValue(RowSpanProperty));
 }
示例#17
0
 public static SearchHandler GetSearchHandler(BindableObject obj) => (SearchHandler)obj.GetValue(SearchHandlerProperty);
 public static bool GetIsHeadless(BindableObject bindable)
 => (bool)bindable.GetValue(IsHeadlessProperty);
示例#19
0
 public static bool GetTabBarIsVisible(BindableObject obj) => (bool)obj.GetValue(TabBarIsVisibleProperty);
 public static Point GetHeadlessOffset(BindableObject bindable)
 => (Point)bindable.GetValue(HeadlessOffsetProperty);
示例#21
0
 /// <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));
 }
示例#22
0
 public static Color GetShellTabBarForegroundColor(BindableObject obj) => (Color)obj.GetValue(ShellTabBarForegroundColorProperty);
示例#23
0
 public static string GetPluralMessage(DependencyObject o)
 {
     return(o.GetValue(PluralMessageProperty) as string);
 }
示例#24
0
 public static Color GetShellTitleColor(BindableObject obj) => (Color)obj.GetValue(ShellTitleColorProperty);
示例#25
0
 public static StringModifier GetModifier(DependencyObject o)
 {
     return((StringModifier)o.GetValue(ModifierProperty));
 }
示例#26
0
 public static Color GetShellUnselectedColor(BindableObject obj) => (Color)obj.GetValue(ShellUnselectedColorProperty);
示例#27
0
 public static string GetToolTip(DependencyObject o)
 {
     return((string)o.GetValue(ToolTipProperty));
 }
示例#28
0
 public static BackButtonBehavior GetBackButtonBehavior(BindableObject obj) => (BackButtonBehavior)obj.GetValue(BackButtonBehaviorProperty);
示例#29
0
 public static string GetComment(DependencyObject o)
 {
     return(o.GetValue(CommentProperty) as string);
 }
示例#30
0
        internal override bool GetState(BindableObject bindable)
        {
            object newValue = bindable.GetValue(_boundProperty);

            return(EqualsToValue(newValue));
        }