コード例 #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
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 public static bool GetSetPaddingInsets(BindableObject obj) => (bool)obj.GetValue(SetPaddingInsetsProperty);
コード例 #7
0
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 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
ファイル: FontElement.cs プロジェクト: MIliev11/Samples
 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
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 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
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 public static SearchHandler GetSearchHandler(BindableObject obj) => (SearchHandler)obj.GetValue(SearchHandlerProperty);
コード例 #18
0
 public static bool GetIsHeadless(BindableObject bindable)
 => (bool)bindable.GetValue(IsHeadlessProperty);
コード例 #19
0
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 public static bool GetTabBarIsVisible(BindableObject obj) => (bool)obj.GetValue(TabBarIsVisibleProperty);
コード例 #20
0
 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
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 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
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 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
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 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
ファイル: Shell.cs プロジェクト: markjcarew/Xamarin.Forms
 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));
        }