internal void Initialize(TagsTextBoxFooter inline) { InputPlaceholder = inline; InputPlaceholder.TextChanged += OnTextChanged; ItemsWrapPanel = (TagsWrapPanel)ItemsPanelRoot; InputPlaceholder.KeyDown += OnKeyDown; ItemsWrapPanel.LayoutUpdated += OnWrapLayoutUpdated; var bindPlaceholder = new Binding(); bindPlaceholder.Path = new PropertyPath("PlaceholderText"); bindPlaceholder.Source = this; var bindCanShow = new Binding(); bindCanShow.Path = new PropertyPath("CanShowPlaceholder"); bindCanShow.Source = this; //var bindText = new Binding(); //bindText.Path = new PropertyPath("Text"); //bindText.Source = InputPlaceholder; //bindText.Mode = BindingMode.TwoWay; InputPlaceholder.SetBinding(TextBox.PlaceholderTextProperty, bindPlaceholder); InputPlaceholder.SetBinding(TagsTextBoxFooter.CanShowPlaceholderProperty, bindCanShow); //SetBinding(TextProperty, bindText); }
protected override Size MeasureOverride(Size constraint) { var inline = Children.OfType<TagsTextBoxFooter>().FirstOrDefault(); if (inline == null) { inline = new TagsTextBoxFooter(); Children.Add(inline); if (_textBox == null) _textBox = this.Ancestors<TagsTextBox>().FirstOrDefault() as TagsTextBox; if (_textBox != null) _textBox.Initialize(inline); } // Variables tracking the size of the current line, the total size // measured so far, and the maximum size available to fill. Note // that the line might represent a row or a column depending on the // orientation. Orientation o = Orientation.Horizontal; OrientedSize lineSize = new OrientedSize(o); OrientedSize totalSize = new OrientedSize(o); OrientedSize maximumSize = new OrientedSize(o, constraint.Width, constraint.Height); // Determine the constraints for individual items double itemWidth = double.NaN; double itemHeight = double.NaN; bool hasFixedWidth = !itemWidth.IsNaN(); bool hasFixedHeight = !itemHeight.IsNaN(); Size itemSize = new Size( hasFixedWidth ? itemWidth : constraint.Width, hasFixedHeight ? itemHeight : constraint.Height); // Measure each of the Children foreach (UIElement element in Children) { if (element == Children.Last()) { var desiredSize = constraint.Width - lineSize.Width; if (desiredSize < (element as TextBox).MinWidth) { (element as TextBox).Width = constraint.Width; } else { (element as TextBox).Width = desiredSize; } } // Determine the size of the element element.Measure(itemSize); OrientedSize elementSize = new OrientedSize( o, hasFixedWidth ? itemWidth : element.DesiredSize.Width, hasFixedHeight ? itemHeight : element.DesiredSize.Height); // If this element falls of the edge of the line if (NumericExtensions.IsGreaterThan(lineSize.Direct + elementSize.Direct, maximumSize.Direct)) { // Update the total size with the direct and indirect growth // for the current line totalSize.Direct = Math.Max(lineSize.Direct, totalSize.Direct); totalSize.Indirect += lineSize.Indirect; // Move the element to a new line lineSize = elementSize; // If the current element is larger than the maximum size, // place it on a line by itself if (NumericExtensions.IsGreaterThan(elementSize.Direct, maximumSize.Direct)) { // Update the total size for the line occupied by this // single element totalSize.Direct = Math.Max(elementSize.Direct, totalSize.Direct); totalSize.Indirect += elementSize.Indirect; // Move to a new line lineSize = new OrientedSize(o); } } else { // Otherwise just add the element to the end of the line lineSize.Direct += elementSize.Direct; lineSize.Indirect = Math.Max(lineSize.Indirect, elementSize.Indirect); } } // Update the total size with the elements on the last line totalSize.Direct = Math.Max(lineSize.Direct, totalSize.Direct); totalSize.Indirect += lineSize.Indirect; // Return the total size required as an un-oriented quantity return new Size(totalSize.Width, totalSize.Height); }