Esempio n. 1
0
 void SetAccesibilityFocus(MvvmAspire.Controls.Label element)
 {
     if (UIAccessibility.IsVoiceOverRunning && element.AccesibilitySetFocus)
     {
         UIAccessibility.PostNotification(UIAccessibilityPostNotification.ScreenChanged, Control);
         element.AccesibilitySetFocus = false;
     }
 }
Esempio n. 2
0
        void _tabChildren_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int index = e.NewStartingIndex;
                foreach (TabChild tc in e.NewItems)
                {
                    tc.SetBinding(TabChild.AnimateTabSwitchProperty, new Binding {
                            Source = this, Path = "AnimateTabSwitch"
                        });

                    int idx    = index++;
                    var column = new ColumnDefinition();
                    column.SetBinding(ColumnDefinition.WidthProperty, new Binding {
                            Source = tc, Path = "ColumnWidth"
                        });
                    this.GridView.ColumnDefinitions.Insert(idx, column);

                    var element = new  MvvmAspire.Controls.Button
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                    };

                    if (Device.RuntimePlatform == Device.WPF)
                    {
                        element.BackgroundImage = "ButtonTabStyle";
                        element.BorderWidth     = 0;
                    }

                    element.XAlign = Xamarin.Forms.TextAlignment.Center;
                    element.SetBinding(Button.RefitTextEnabledProperty, new Binding {
                            Source = tc, Path = "RefitTextEnabled"
                        });
                    element.SetBinding(Button.TextProperty, new Binding {
                            Source = tc, Path = "Text"
                        });
                    element.SetBinding(Button.TextColorProperty, new Binding {
                            Source = tc, Path = "TextColor"
                        });
                    element.SetBinding(Button.CornerRadiusProperty, new Binding {
                            Source = tc, Path = "CornerRadius"
                        });
                    element.SetBinding(Button.FontSizeProperty, new Binding {
                            Source = tc, Path = "FontSize"
                        });
                    //  element.SetBinding(Button.FontStyleProperty, new Binding { Source = tc, Path = "FontStyle" });
                    element.SetBinding(Button.BorderRadiusProperty, new Binding {
                            Source = tc, Path = "BorderRadius"
                        });
                    element.SetBinding(Button.ImageLeftHeightProperty, new Binding {
                            Source = tc, Path = "ImageLeftHeight"
                        });
                    element.SetBinding(Button.ImageLeftWidthProperty, new Binding {
                            Source = tc, Path = "ImageLeftWidth"
                        });
                    element.SetBinding(Button.ImageRightHeightProperty, new Binding {
                            Source = tc, Path = "ImageRightHeight"
                        });
                    element.SetBinding(Button.ImageRightWidthProperty, new Binding {
                            Source = tc, Path = "ImageRightWidth"
                        });
                    element.SetBinding(Button.ImageLeftProperty, new Binding {
                            Source = tc, Path = "ImageLeft"
                        });
                    element.SetBinding(Button.ImageRightProperty, new Binding {
                            Source = tc, Path = "ImageRight"
                        });
                    element.SetBinding(Button.HeightRequestProperty, new Binding("TabHeight", source: this));
                    element.SetBinding(Button.CenterImageProperty, new Binding {
                            Source = tc, Path = "CenterImage"
                        });
                    element.SetBinding(Button.PaddingProperty, new Binding {
                            Source = tc, Path = "TextPadding"
                        });
                    element.SetBinding(Button.SelectedImageLeftProperty, new Binding {
                            Source = tc, Path = "SelectedImageLeft"
                        });
                    element.SetBinding(Button.SelectedImageRightProperty, new Binding {
                            Source = tc, Path = "SelectedImageRight"
                        });


                    //if (Device.RuntimePlatform == Device.iOS)
                    element.PropertyChanged += ButtonPropertyChanged;
                    element.Clicked         += element_Clicked;


                    var box = new BoxView();        // { HorizontalOptions = LayoutOptions.End };
                    box.SetBinding(BoxView.WidthRequestProperty, new Binding()
                        {
                            Source = this, Path = "TabDividerWidth"
                        });
                    box.SetBinding(BoxView.ColorProperty, new Binding()
                        {
                            Source = this, Path = "TabDividerColor"
                        });

                    var layout = new Grid
                    {
                        ColumnSpacing = 0,
                        Padding       = 0
                    };
                    if (e.NewStartingIndex > 0)
                    {
                        layout.ColumnDefinitions = new ColumnDefinitionCollection
                        {
                            new ColumnDefinition {
                                Width = new GridLength(1, GridUnitType.Auto)
                            },
                            new ColumnDefinition {
                                Width = new GridLength(1, GridUnitType.Star)
                            }
                        };
                        layout.Children.Add(box, 0, 0);
                        layout.Children.Add(element, 1, 0);
                    }
                    else
                    {
                        layout.ColumnDefinitions = new ColumnDefinitionCollection
                        {
                            new ColumnDefinition {
                                Width = new GridLength(1, GridUnitType.Star)
                            }
                        };
                        layout.Children.Add(element, 0, 0);
                    }

                    this.GridView.Children.Add(layout, idx, 0);


                    var subText = new  MvvmAspire.Controls.Label
                    {
                        VerticalOptions         = LayoutOptions.End,
                        VerticalTextAlignment   = Xamarin.Forms.TextAlignment.End,
                        HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Center,
                        MaxLines      = 1,
                        LineBreakMode = LineBreakMode.NoWrap
                    };
                    subText.SetBinding(MvvmAspire.Controls.Label.TextProperty, new Binding(path: "SubText", source: tc));
                    subText.SetBinding(MvvmAspire.Controls.Label.FontSizeProperty, new Binding(path: "SubTextFontSize", source: tc));
                    subText.SetBinding(MvvmAspire.Controls.Label.TextColorProperty, new Binding(path: "SubTextColor", source: tc));
                    subText.SetBinding(MvvmAspire.Controls.Label.IsVisibleProperty, new Binding(path: "SubText", source: tc, converter: new StringToBoolConverter()));

                    this.GridView.Children.Add(subText, idx, 0);

                    this.TabContentView.Children.Add(tc, 0, 1);

                    if (SelectedIndex == -1)
                    {
                        SelectedIndex = idx;
                    }
                    else
                    {
                        tc.Opacity   = 0;
                        tc.IsVisible = false;
                        this.TabContentView.LowerChild(tc);
                    }

                    if (tc.SetCurrentSelected)
                    {
                        SelectedIndex = idx;
                    }
                    if (idx == SelectedIndex)
                    {
                        if (tc.SelectedBackgroundImage != null && tc.SelectedBackgroundImage.File != null)
                        {
                            element.BackgroundImage = tc.SelectedBackgroundImage;
                        }

                        element.BackgroundColor = tc.SelectedBackgroundColor;
                        element.TextColor       = tc.SelectedTextColor;
                        subText.TextColor       = tc.SelectedTextColor;
                    }
                    else
                    {
                        if (tc.BackgroundImage != null && tc.BackgroundImage.File != null)
                        {
                            element.BackgroundImage = tc.BackgroundImage;
                        }

                        element.BackgroundColor = tc.BackgroundColor;
                        element.TextColor       = tc.TextColor;
                        subText.TextColor       = tc.TextColor;
                    }
                }
            }
            break;

            case NotifyCollectionChangedAction.Move:
            {
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                int index = e.OldStartingIndex;
                this.GridView.ColumnDefinitions.RemoveAt(index);

                var button  = this.GridView.Children.FirstOrDefault(c => Grid.GetColumn(c) == index && Grid.GetRow(c) == 0);
                var boxView = this.GridView.Children.FirstOrDefault(c => Grid.GetColumn(c) == index && Grid.GetRow(c) == 1);
                this.GridView.Children.Remove(button);
                this.GridView.Children.Remove(boxView);

                for (int i = e.OldStartingIndex + 1; i < this.GridView.Children.Count; i++)
                {
                    button  = this.GridView.Children.FirstOrDefault(c => Grid.GetColumn(c) == i && Grid.GetRow(c) == 0);
                    boxView = this.GridView.Children.FirstOrDefault(c => Grid.GetColumn(c) == i && Grid.GetRow(c) == 1);

                    Grid.SetColumn(button, i - 1);
                    Grid.SetColumn(boxView, i - 1);
                }
                this.TabContentView.Children.RemoveAt(index + 1);
                RemoveTabChild(index);
            }
            break;

            case NotifyCollectionChangedAction.Reset:
            {
                SelectedIndex = -1;
                this.GridView.ColumnDefinitions.Clear();
                this.GridView.Children.Clear();
                while (this.TabContentView.Children.Count > 0)
                {
                    RemoveTabChild(0);
                }
            }
            break;
            }
        }