Exemplo n.º 1
0
            /**
             * @brief OnApplyTemplate override. This function sets up the bindings between the textblock_, textbox_ controls and the Text property.
             * @see https://msdn.microsoft.com/nl-nl/library/system.windows.frameworkelement.onapplytemplate(v=vs.110).aspx
             * @remark If no adornerlayer can be found an error will be thrown which can be viewed in the logger. This will also stop the adorner and TextBox from being created meaning this control will be used like a normal textblcok control.
             */
            public override void OnApplyTemplate()
            {
                textblock_ = Template.FindName("textblock", this) as TextBlock;
                layer_     = AdornerLayer.GetAdornerLayer(textblock_);

                Binding widthbinding = new Binding();

                widthbinding.Source = this;
                widthbinding.Path   = new PropertyPath("Width");
                textblock_.SetBinding(TextBlock.WidthProperty, widthbinding);

                Binding textbinding = new Binding();

                textbinding.Source = this;
                textbinding.Path   = new PropertyPath("Text");
                textblock_.SetBinding(TextBlock.TextProperty, textbinding);

                if (layer_ == null)
                {
                    Log.Write(Log.Verbosity.kFatal, "EditBox: AdornerLayer not found");
                }
                else
                {
                    textbox_ = new TextBox();
                    textbox_.LostKeyboardFocus += HandleLostKeyboardFocus;
                    textbox_.KeyDown           += HandleKeyDown;
                    adorner_ = new EditBoxAdorner(textblock_, textbox_);
                }

                ItemsControl container = GetDependencyObjectFromVisualTree(this, typeof(ItemsControl)) as ItemsControl;
                Control      item      = container.ItemContainerGenerator.ContainerFromItem(this) as EditBox;

                parent_ = item == null ? container : item;

                if (parent_ != null)
                {
                    parent_.LostKeyboardFocus += HandleLostKeyboardFocus;
                    parent_.MouseDoubleClick  += Control_MouseDoubleClick;
                    parent_.KeyDown           += Control_KeyDown;
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Called when the tree for the EditBox has been generated.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            TextBlock textBlock = GetTemplateChild("PART_TextBlockPart")
                   as TextBlock;
            Debug.Assert(textBlock != null, "No TextBlock!");

            if (EditType == AttributeType.Date)
                editControl = new DatePicker();
            else if (EditType == AttributeType.Int)
                editControl = new NumericBox();
            else
                editControl = new TextBox();

            (editControl as Control).Padding = new Thickness(-1);
            (editControl as Control).Margin = new Thickness(-3, -1, -3, -1);
            _adorner = new EditBoxAdorner(textBlock, editControl);
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(textBlock);
            layer.Add(_adorner);
            _adorner.UpdateVisibilty(false);

            editControl.PreviewKeyDown += new KeyEventHandler(OnTextBoxKeyDown);
            editControl.LostKeyboardFocus +=
              new KeyboardFocusChangedEventHandler(OnTextBoxLostKeyboardFocus);

            //Receive notification of the event to handle the column
            //resize.
            HookTemplateParentResizeEvent();

            //Capture the resize event to  handle ListView resize cases.
            HookItemsControlEvents();

            _listViewItem = GetDependencyObjectFromVisualTree(this,
                typeof(ListViewItem)) as ListViewItem;

            Debug.Assert(_listViewItem != null, "No ListViewItem found");
        }