コード例 #1
0
ファイル: SignaturePad.cs プロジェクト: delort/SignaturePad
        private void Initialize()
        {
            const int ThinPad    = 3;
            const int ThickPad   = 20;
            const int LineHeight = 2;

            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.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
                BackgroundImageView.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Stretch);
                BackgroundImageView.SetValue(Grid.RowProperty, 0);
                Children.Add(BackgroundImageView);
            }

            // add the main signature view
            {
                SignaturePadCanvas = new SignaturePadCanvasView();
                SignaturePadCanvas.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
                SignaturePadCanvas.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Stretch);
                SignaturePadCanvas.SetValue(Grid.RowProperty, 0);
                SignaturePadCanvas.StrokeCompleted += (sender, e) =>
                {
                    UpdateUi();
                    StrokeCompleted?.Invoke(this, EventArgs.Empty);
                };
                SignaturePadCanvas.Cleared += (sender, e) => Cleared?.Invoke(this, EventArgs.Empty);
                Children.Add(SignaturePadCanvas);
            }

            // add the caption
            {
                Caption = new TextBlock()
                {
                    Text          = "Sign here.",
                    FontSize      = 11,
                    Foreground    = new SolidColorBrush(Colors.Gray),
                    TextAlignment = TextAlignment.Center,
                    Margin        = new Thickness(ThinPad)
                };
                Caption.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
                Caption.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Bottom);
                Caption.SetValue(Grid.RowProperty, 1);
                Children.Add(Caption);
            }

            // add the signature line
            {
                SignatureLine = new Border()
                {
                    Background = new SolidColorBrush(Colors.Gray),
                    Height     = LineHeight,
                    Margin     = new Thickness(ThickPad, 0, ThickPad, 0)
                };
                SignatureLine.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
                SignatureLine.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Bottom);
                Children.Add(SignatureLine);
            }

            // add the prompt
            {
                SignaturePrompt = new TextBlock()
                {
                    Text       = "X",
                    FontSize   = 20,
                    FontWeight = FontWeights.Bold,
                    Margin     = new Thickness(ThickPad, 0, 0, ThinPad)
                };
                SignaturePrompt.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                SignaturePrompt.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Bottom);
                Children.Add(SignaturePrompt);
            }

            // add the clear label
            {
                ClearLabel = new TextBlock()
                {
                    Text       = "Clear",
                    FontSize   = 11,
                    FontWeight = FontWeights.Bold,
                    Visibility = Visibility.Collapsed,
                    Foreground = new SolidColorBrush(Colors.Gray),
                    Margin     = new Thickness(0, ThickPad, ThickPad, 0)
                };
                ClearLabel.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Right);
                ClearLabel.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top);
                Children.Add(ClearLabel);

                // attach the "clear" command
                ClearLabel.MouseLeftButtonUp += (sender, e) => Clear();
            }

            // clear / initialize the view
            Clear();
        }
コード例 #2
0
        private void Initialize()
        {
            // add the background view
            {
                BackgroundImageView = new ImageView(Context)
                {
                    Id = GenerateId(this),
                    LayoutParameters = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent)
                };
                AddView(BackgroundImageView);
            }

            // add the main signature view
            {
                SignaturePadCanvas = new SignaturePadCanvasView(Context)
                {
                    Id = GenerateId(this),
                    LayoutParameters = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent)
                };
                SignaturePadCanvas.StrokeCompleted += (sender, e) =>
                {
                    UpdateUi();
                    StrokeCompleted?.Invoke(this, EventArgs.Empty);
                };
                SignaturePadCanvas.Cleared += (sender, e) => Cleared?.Invoke(this, EventArgs.Empty);
                AddView(SignaturePadCanvas);
            }

            // add the caption
            {
                Caption = new TextView(Context)
                {
                    Id   = GenerateId(this),
                    Text = "Sign Here"
                };
                var layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent)
                {
                    AlignWithParent = true,
                    BottomMargin    = 6
                };
                layout.AddRule(LayoutRules.AlignBottom);
                layout.AddRule(LayoutRules.CenterHorizontal);
                Caption.LayoutParameters = layout;
                Caption.SetIncludeFontPadding(true);
                Caption.SetPadding(0, 0, 0, 6);
                AddView(Caption);
            }

            // add the signature line
            {
                SignatureLine = new View(Context)
                {
                    Id = GenerateId(this)
                };
                SignatureLine.SetBackgroundColor(Color.Gray);
                var layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, 1);
                layout.SetMargins(10, 0, 10, 5);
                layout.AddRule(LayoutRules.Above, Caption.Id);
                SignatureLine.LayoutParameters = layout;
                AddView(SignatureLine);
            }

            // add the prompt
            {
                SignaturePrompt = new TextView(Context)
                {
                    Id   = GenerateId(this),
                    Text = "X"
                };
                SignaturePrompt.SetTypeface(null, TypefaceStyle.Bold);
                var layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent)
                {
                    LeftMargin = 11
                };
                layout.AddRule(LayoutRules.Above, SignatureLine.Id);
                SignaturePrompt.LayoutParameters = layout;
                AddView(SignaturePrompt);
            }

            // add the clear label
            {
                ClearLabel = new TextView(Context)
                {
                    Id         = GenerateId(this),
                    Text       = "Clear",
                    Visibility = ViewStates.Invisible
                };
                var layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent)
                {
                    AlignWithParent = true
                };
                layout.SetMargins(0, 10, 22, 0);
                layout.AddRule(LayoutRules.AlignRight);
                layout.AddRule(LayoutRules.AlignTop);
                ClearLabel.LayoutParameters = layout;
                AddView(ClearLabel);

                // attach the "clear" command
                ClearLabel.Click += (sender, e) => Clear();
            }

            // clear / initialize the view
            Clear();
        }
コード例 #3
0
        private void Initialize(bool baseProperties = true)
        {
            // add the background view
            {
                BackgroundImageView = new UIImageView();
                AddSubview(BackgroundImageView);
            }

            // add the main signature view
            {
                SignaturePadCanvas = new SignaturePadCanvasView();
                SignaturePadCanvas.StrokeCompleted += (sender, e) =>
                {
                    UpdateUi();
                    StrokeCompleted?.Invoke(this, EventArgs.Empty);
                };
                SignaturePadCanvas.Cleared += (sender, e) => Cleared?.Invoke(this, EventArgs.Empty);
                AddSubview(SignaturePadCanvas);
            }

            // add the caption
            {
                Caption = new UILabel()
                {
                    Text            = "Sign here.",
                    Font            = UIFont.BoldSystemFontOfSize(11f),
                    BackgroundColor = UIColor.Clear,
                    TextColor       = UIColor.Gray,
                    TextAlignment   = UITextAlignment.Center
                };
                AddSubview(Caption);
            }

            // add the signature line
            {
                SignatureLine = new UIView()
                {
                    BackgroundColor = UIColor.Gray
                };
                AddSubview(SignatureLine);
            }

            // add the prompt
            {
                SignaturePrompt = new UILabel()
                {
                    Text            = "X",
                    Font            = UIFont.BoldSystemFontOfSize(20f),
                    BackgroundColor = UIColor.Clear,
                    TextColor       = UIColor.Gray
                };
                AddSubview(SignaturePrompt);
            }

            // add the clear label
            {
                ClearLabel = UIButton.FromType(UIButtonType.Custom);
                ClearLabel.SetTitle("Clear", UIControlState.Normal);
                ClearLabel.Font            = UIFont.BoldSystemFontOfSize(11f);
                ClearLabel.BackgroundColor = UIColor.Clear;
                ClearLabel.SetTitleColor(UIColor.Gray, UIControlState.Normal);
                AddSubview(ClearLabel);

                // attach the "clear" command
                ClearLabel.TouchUpInside += (sender, e) => Clear();
            }

            // clear / initialize the view
            Clear();
        }
コード例 #4
0
        private void Initialize(bool baseProperties = true)
        {
            // add the background view
            {
                BackgroundImageView = new UIImageView();
                AddSubview(BackgroundImageView);
            }

            // add the main signature view
            {
                SignaturePadCanvas = new SignaturePadCanvasView();
                SignaturePadCanvas.StrokeCompleted += delegate
                {
                    OnSignatureStrokeCompleted();
                };
                SignaturePadCanvas.DblTapped += delegate
                {
                    OnDoubleTapped();
                };
                SignaturePadCanvas.Cleared += delegate
                {
                    OnSignatureCleared();
                };
                AddSubview(SignaturePadCanvas);
            }

            // add the caption
            {
                Caption = new UILabel()
                {
                    BackgroundColor = UIColor.Clear,
                    TextAlignment   = UITextAlignment.Center,
                    Font            = UIFont.SystemFontOfSize(DefaultFontSize),
                    Text            = DefaultCaptionText,
                    TextColor       = SignaturePadDarkColor,
                };
                AddSubview(Caption);
            }

            // add the signature line
            {
                SignatureLine = new UIView()
                {
                    BackgroundColor = SignaturePadDarkColor,
                };
                SignatureLineWidth   = DefaultLineThickness;
                SignatureLineSpacing = DefaultNarrowSpacing;
                AddSubview(SignatureLine);
            }

            // add the prompt
            {
                SignaturePrompt = new UILabel()
                {
                    BackgroundColor = UIColor.Clear,
                    Font            = UIFont.BoldSystemFontOfSize(DefaultFontSize),
                    Text            = DefaultPromptText,
                    TextColor       = SignaturePadDarkColor,
                };
                AddSubview(SignaturePrompt);
            }

            // add the clear label
            {
                ClearLabel = UIButton.FromType(UIButtonType.Custom);
                ClearLabel.BackgroundColor = UIColor.Clear;
                ClearLabel.Font            = UIFont.BoldSystemFontOfSize(DefaultFontSize);
                ClearLabel.SetTitle(DefaultClearLabelText, UIControlState.Normal);
                ClearLabel.SetTitleColor(SignaturePadDarkColor, UIControlState.Normal);
                AddSubview(ClearLabel);

                // attach the "clear" command
                ClearLabel.TouchUpInside += delegate
                {
                    OnClearTapped();
                };
            }

            Padding = new UIEdgeInsets(DefaultWideSpacing, DefaultWideSpacing, DefaultNarrowSpacing, DefaultWideSpacing);

            // clear / initialize the view
            UpdateUi();
        }