public void ClosePopup() { if (pView != null) { this.layout.Children.Remove(pView); pView = null; } if (backDrop != null) { this.layout.Children.Remove(backDrop); backDrop = null; } }
public void ShowPopup(PopupView view, PopupBounds bounds, int padding) { pView = new PView() { Content = view, Border = new PancakeView.Border() { Color = view.BorderColor }, CornerRadius = view.CornerRadius, IsClippedToBounds = view.IsClippedToBounds, BackgroundColor = Color.White, Padding = padding, Shadow = new PancakeView.DropShadow() { Color = Color.White, Offset = new Point(1, 1), BlurRadius = 1, Opacity = 0.7f } }; backDrop = new StackLayout() { BackgroundColor = Color.Black, Opacity = 0.5 }; AbsoluteLayout.SetLayoutBounds(backDrop, new Rectangle(1, 1, 1, 1)); AbsoluteLayout.SetLayoutFlags(backDrop, AbsoluteLayoutFlags.All); this.layout.Children.Add(backDrop); AbsoluteLayout.SetLayoutBounds(pView, bounds.ToRectangle()); AbsoluteLayout.SetLayoutFlags(pView, AbsoluteLayoutFlags.All); this.layout.Children.Add(pView); view.BindingContext = this.BindingContext; if (view.AnimateOpen) { pView.ScaleTo(0.99, 200).ContinueWith(async(t) => { await pView.ScaleTo(1, 200); }); } }
private void SegmentClicked(Xamarin.Forms.PancakeView.PancakeView view) { var stackLayout = (StackLayout)this.Content; foreach (var item in stackLayout.Children) { var pancake = (Xamarin.Forms.PancakeView.PancakeView)item; var lbl = (Label)((StackLayout)pancake.Content).Children[0]; if (pancake == view) { SelectedIndex = stackLayout.Children.IndexOf(pancake); pancake.BackgroundColor = this.SelectedBackground; lbl.TextColor = this.SelectedTextColor; } else { pancake.BackgroundColor = this.UnselectedBackground; lbl.TextColor = this.UnselectedTextColor; } } Command?.Execute(SelectedIndex); }
public void RenderControl() { if (ItemsSource != null) { _layout = new StackLayout() { Spacing = -1, Orientation = StackOrientation.Horizontal }; for (int x = 0; x < ItemsSource.Count; x++) { var seg = ItemsSource[x]; var cornerRadius = new CornerRadius(0); var backgroundColor = Color.Default; var textColor = Color.Default; if (x == 0) { cornerRadius = new CornerRadius(this.CornerRadius, 0, this.CornerRadius, 0); } if (x == ItemsSource.Count - 1) { cornerRadius = new CornerRadius(0, this.CornerRadius, 0, this.CornerRadius); } if (x == SelectedIndex) { backgroundColor = SelectedBackground; textColor = SelectedTextColor; } else { backgroundColor = UnselectedBackground; textColor = UnselectedTextColor; } if (seg == ItemsSource.First()) { cornerRadius = new CornerRadius(this.CornerRadius, 0, this.CornerRadius, 0); } if (seg == ItemsSource.Last()) { cornerRadius = new CornerRadius(0, this.CornerRadius, 0, this.CornerRadius); } var view = new Xamarin.Forms.PancakeView.PancakeView() { CornerRadius = cornerRadius, Border = new PancakeView.Border() { Color = this.SelectedBackground, Thickness = 1 }, BackgroundColor = backgroundColor, HorizontalOptions = LayoutOptions.FillAndExpand, Content = new StackLayout() { Children = { new Label() { TextColor = textColor, Text = seg, FontFamily = this.FontFamily, FontSize = this.FontSize, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center, } } } }; view.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(() => { SegmentClicked(view); }) }); _layout.Children.Add(view); } this.Content = _layout; } }