Esempio n. 1
0
        protected virtual void OnTabbedPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var element = sender as Element;

            if (element == null)
            {
                return;
            }

            BadgeView badgeView;

            if (!BadgeViews.TryGetValue(element, out badgeView))
            {
                return;
            }

            if (e.PropertyName == CustomTabbedPage.BadgeTextProperty.PropertyName)
            {
                badgeView.Text = CustomTabbedPage.GetBadgeText(element);
                return;
            }

            if (e.PropertyName == CustomTabbedPage.BadgeColorProperty.PropertyName)
            {
                badgeView.BadgeColor = CustomTabbedPage.GetBadgeColor(element).ToAndroid();
            }
        }
        protected virtual void OnTabbedPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var element = sender as Element;

            if (element == null)
            {
                return;
            }

            var tabItems = Control.GetDescendantsOfType <TabItem>();
            var tabItem  = tabItems.FirstOrDefault(t => t.Label == ((Page)element).Title);

            if (tabItem == null)
            {
                return;
            }

            if (e.PropertyName == CustomTabbedPage.BadgeTextProperty.PropertyName)
            {
                tabItem.BadgeText = CustomTabbedPage.GetBadgeText(element);
                return;
            }

            if (e.PropertyName == CustomTabbedPage.BadgeColorProperty.PropertyName)
            {
                tabItem.BadgeColor = new Xaml.Media.SolidColorBrush(
                    ColorHelper.XamarinFormColorToWindowsColor(
                        CustomTabbedPage.GetBadgeColor(element)));
            }

            SetSelectedTab(Control);
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is Page)
            {
                var badgeText = CustomTabbedPage.GetBadgeText((Page)value);

                return(badgeText);
            }

            return(string.Empty);
        }
Esempio n. 4
0
        private void AddTabBadge(int tabIndex)
        {
            var element = Element.Children[tabIndex];
            var view    = _tabLayout?.GetTabAt(tabIndex).CustomView ?? _tabStrip?.GetChildAt(tabIndex);

            var badgeView = (view as ViewGroup)?.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                var imageView = (view as ViewGroup)?.FindChildOfType <ImageView>();

                var badgeTarget = imageView?.Drawable != null
                    ? (Android.Views.View)imageView
                    : (view as ViewGroup)?.FindChildOfType <TextView>();

                // Create badge for tab
                badgeView = new BadgeView(Context, badgeTarget);
            }

            BadgeViews[element] = badgeView;

            // Get text
            var badgeText = CustomTabbedPage.GetBadgeText(element);

            badgeView.Text = badgeText;

            // Set color if not default
            var tabColor = CustomTabbedPage.GetBadgeColor(element);

            if (tabColor != Xamarin.Forms.Color.Default)
            {
                badgeView.BadgeColor = tabColor.ToAndroid();
            }

            element.PropertyChanged += OnTabbedPagePropertyChanged;
        }
Esempio n. 5
0
        private void UpdateTabBadgeText(UITabBarItem tabBarItem, Element element)
        {
            var text = CustomTabbedPage.GetBadgeText(element);

            tabBarItem.BadgeValue = string.IsNullOrEmpty(text) ? null : text;
        }