Example #1
0
        private TextBox CreateSignatureTextBox(BindableText text, Thickness margin, int page, int of)
        {
            TextBox tb = new TextBox {
                AcceptsReturn = true, Background = Brushes.Transparent, BorderThickness = new Thickness(0), Margin = margin
            };

            Binding CreateBinding()
            {
                var binding = new Binding(nameof(text.Text));

                binding.Mode = BindingMode.TwoWay;
                binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                binding.Source = text;
                return(binding);
            }

            var rawTextBinding = CreateBinding();

            var pageCountBinding = CreateBinding();

            pageCountBinding.Converter = new PageCountConverter(page, of);

            tb.GotKeyboardFocus += (sender, e) =>
                                   tb.SetBinding(TextBox.TextProperty, rawTextBinding);
            tb.LostKeyboardFocus += (sender, e) =>
                                    tb.SetBinding(TextBox.TextProperty, pageCountBinding);

            tb.SetBinding(TextBox.TextProperty, pageCountBinding);

            return(tb);
        }
Example #2
0
        /// <summary>
        /// Add an editable TextBox to all pages of the document (returns specified textbox, for focusing)
        /// </summary>
        public TextBox InitialAddSignatureTb(double x, double y, int textboxToReturnPageIndex)
        {
            // match x and y coordinates to height/width of the content of the page
            x = x - Padding.Left;
            y = y - Padding.Top;

            if (x < 0 || x > ContentWidth)
            {
                return(null);
            }
            if (y < 0 || y > ContentHeight)
            {
                return(null);
            }

            // approximately center textbox on coordinates
            x -= 2;
            y -= 8;

            var bindableText    = new BindableText();
            var signatureChange = new SignatureChange(bindableText, x, y);

            return(AddSignatureNoCopy(signatureChange, textboxToReturnPageIndex));
        }