private void Initialize() { const int ThinPad = 3; const int ThickPad = 12; const int LineHeight = 2; RowSpacing = 0; ColumnSpacing = 0; RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); // add the background view { BackgroundImageView = new Image(); BackgroundImageView.SetValue(Grid.HorizontalOptionsProperty, LayoutOptions.FillAndExpand); BackgroundImageView.SetValue(Grid.VerticalOptionsProperty, LayoutOptions.FillAndExpand); BackgroundImageView.SetValue(Grid.RowProperty, 0); Children.Add(BackgroundImageView); } // add the main signature view { SignaturePadCanvas = new SignaturePadCanvasView(); SignaturePadCanvas.SetValue(Grid.HorizontalOptionsProperty, LayoutOptions.FillAndExpand); SignaturePadCanvas.SetValue(Grid.VerticalOptionsProperty, LayoutOptions.FillAndExpand); SignaturePadCanvas.SetValue(Grid.RowProperty, 0); SignaturePadCanvas.SetValue(Grid.RowSpanProperty, 2); SignaturePadCanvas.StrokeCompleted += (sender, e) => UpdateUi(); Children.Add(SignaturePadCanvas); } // add the caption { CaptionLabel = new Label { Text = "Sign here.", FontSize = 11, TextColor = Color.Gray, HorizontalTextAlignment = TextAlignment.Center, Margin = new Thickness(ThinPad) }; CaptionLabel.SetValue(Grid.HorizontalOptionsProperty, LayoutOptions.FillAndExpand); CaptionLabel.SetValue(Grid.VerticalOptionsProperty, LayoutOptions.End); CaptionLabel.SetValue(Grid.RowProperty, 1); Children.Add(CaptionLabel); } // add the signature line { SignatureLine = new BoxView { BackgroundColor = Color.Gray, HeightRequest = LineHeight, Margin = new Thickness(ThickPad, 0, ThickPad, 0) }; SignatureLine.SetValue(Grid.HorizontalOptionsProperty, LayoutOptions.FillAndExpand); SignatureLine.SetValue(Grid.VerticalOptionsProperty, LayoutOptions.End); Children.Add(SignatureLine); } // add the prompt { SignaturePrompt = new Label { Text = "X", FontSize = 20, FontAttributes = FontAttributes.Bold, Margin = new Thickness(ThickPad, 0, 0, ThinPad) }; SignaturePrompt.SetValue(Grid.HorizontalOptionsProperty, LayoutOptions.Start); SignaturePrompt.SetValue(Grid.VerticalOptionsProperty, LayoutOptions.End); Children.Add(SignaturePrompt); } // add the clear label { ClearLabel = new Label { Text = "Clear", FontSize = 11, FontAttributes = FontAttributes.Bold, IsVisible = false, TextColor = Color.Gray, Margin = new Thickness(0, ThickPad, ThickPad, 0) }; ClearLabel.SetValue(Grid.HorizontalOptionsProperty, LayoutOptions.End); ClearLabel.SetValue(Grid.VerticalOptionsProperty, LayoutOptions.Start); Children.Add(ClearLabel); // attach the "clear" command ClearLabel.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => Clear()) }); } // clear / initialize the view Clear(); }
private void Initialize() { const int ThinPad = 3; const int ThickPad = 12; const int LineHeight = 2; RowSpacing = 0; ColumnSpacing = 0; // create the chrome layout var chromeStack = new StackLayout(); chromeStack.Spacing = 0; chromeStack.Padding = 0; chromeStack.Margin = 0; Children.Add(chromeStack); // add the background view { BackgroundImageView = new Image(); BackgroundImageView.SetValue(View.VerticalOptionsProperty, LayoutOptions.FillAndExpand); chromeStack.Children.Add(BackgroundImageView); } // add the prompt { SignaturePrompt = new Label { Text = "X", FontSize = 20, FontAttributes = FontAttributes.Bold, Margin = new Thickness(ThickPad, 0, 0, 0) }; chromeStack.Children.Add(SignaturePrompt); } // add the signature line { SignatureLine = new BoxView { BackgroundColor = Color.Gray, HeightRequest = LineHeight, Margin = new Thickness(ThickPad, 0, ThickPad, 0) }; chromeStack.Children.Add(SignatureLine); } // add the caption { CaptionLabel = new Label { Text = "Sign here.", FontSize = 11, TextColor = Color.Gray, HorizontalTextAlignment = TextAlignment.Center, Margin = new Thickness(ThinPad) }; chromeStack.Children.Add(CaptionLabel); } // add the main signature view { SignaturePadCanvas = new SignaturePadCanvasView(); SignaturePadCanvas.SetValue(View.HorizontalOptionsProperty, LayoutOptions.Fill); SignaturePadCanvas.SetValue(View.VerticalOptionsProperty, LayoutOptions.Fill); SignaturePadCanvas.StrokeCompleted += (sender, e) => { UpdateUi(); StrokeCompleted?.Invoke(this, EventArgs.Empty); }; SignaturePadCanvas.Cleared += (sender, e) => Cleared?.Invoke(this, EventArgs.Empty); Children.Add(SignaturePadCanvas); } // add the clear label { ClearLabel = new Label { Text = "Clear", FontSize = 11, FontAttributes = FontAttributes.Bold, IsVisible = false, TextColor = Color.Gray, Margin = new Thickness(0, ThickPad, ThickPad, 0) }; ClearLabel.SetValue(View.HorizontalOptionsProperty, LayoutOptions.End); ClearLabel.SetValue(View.VerticalOptionsProperty, LayoutOptions.Start); Children.Add(ClearLabel); // attach the "clear" command ClearLabel.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => Clear()) }); } // clear / initialize the view Clear(); }
public SignaturePadView() { // add the background view BackgroundImageView = new Image { Source = BackgroundImage, Aspect = BackgroundImageAspect, Opacity = BackgroundImageOpacity, InputTransparent = true, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, }; Children.Add(BackgroundImageView); // add the main signature view SignaturePadCanvas = new SignaturePadCanvasView { StrokeColor = StrokeColor, StrokeWidth = StrokeWidth, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill }; Children.Add(SignaturePadCanvas); // add the clear label ClearLabel = new Label { Text = ClearText, FontSize = ClearFontSize, TextColor = ClearTextColor, FontAttributes = FontAttributes.Bold, IsVisible = false, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Start }; Children.Add(ClearLabel); // add the footer bit var footer = new StackLayout { Spacing = 0, Padding = 0, Margin = 0, InputTransparent = true, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.End, }; Children.Add(footer); // add the prompt SignaturePrompt = new Label { Text = PromptText, FontSize = PromptFontSize, TextColor = PromptTextColor, FontAttributes = FontAttributes.Bold, InputTransparent = true, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.End }; footer.Children.Add(SignaturePrompt); // add the signature line SignatureLine = new BoxView { Color = SignatureLineColor, HeightRequest = SignatureLineWidth, InputTransparent = true, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.End }; footer.Children.Add(SignatureLine); // add the caption CaptionLabel = new Label { Text = CaptionText, FontSize = CaptionFontSize, TextColor = CaptionTextColor, HorizontalTextAlignment = TextAlignment.Center, InputTransparent = true, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.End }; footer.Children.Add(CaptionLabel); // set up the main control RowSpacing = 0; ColumnSpacing = 0; Padding = new Thickness(DefaultWideSpacing, DefaultWideSpacing, DefaultWideSpacing, DefaultNarrowSpacing); BackgroundColor = SignaturePadLightColor; // set up events from the controls SignaturePadCanvas.StrokeCompleted += delegate { OnSignatureStrokeCompleted(); }; SignaturePadCanvas.Cleared += delegate { OnSignatureCleared(); }; clearLabelTap = new TapGestureRecognizer { Command = new Command(() => OnClearTapped()) }; ClearLabel.GestureRecognizers.Add(clearLabelTap); OnPaddingChanged(); UpdateUi(); }