/// <summary> /// Gets the parts from the templates. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.scrollViewer = (ScrollViewer)this.GetTemplateChild(ElementScrollViewer); this.textBox = (TextBox)this.GetTemplateChild(ElementTextBox); if (this.textBox != null) { this.textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; this.textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; this.textBox.TextChanged += new TextChangedEventHandler(this.TextBox_TextChanged); this.textBox.GotFocus += new RoutedEventHandler(this.TextBox_GotFocus); this.textBox.LostFocus += new RoutedEventHandler(this.TextBox_LostFocus); #if SILVERLIGHT this.textBox.KeyDown += new KeyEventHandler(this.TextBox_KeyDown); // This is used to make the selection background transparent in Silverlight. #715599DE this.textBox.SelectionBackground = new SolidColorBrush(Color.FromArgb(0x71, 0x55, 0x99, 0xde)); this.textBox.SelectionForeground = new SolidColorBrush(Color.FromArgb(0xff, 0x00, 0x00, 0x00)); #else this.textBox.PreviewKeyDown += new KeyEventHandler(this.TextBox_KeyDown); #endif } this.decoratorItemsControl = (DecoratorItemsControl)this.GetTemplateChild(ElementDecoratorItemsControl); if (this.decoratorItemsControl != null) { this.decoratorItemsControl.ItemsSource = this.textBoxItems; } if (this.scrollViewer != null && this.textBox != null && this.decoratorItemsControl != null) { this.textBox.SelectionChanged += new RoutedEventHandler(this.TextBox_SelectionChanged); } this.watermarkContentPresenter = (ContentPresenter)this.GetTemplateChild(ElementWatermarkContentPresenter); if (this.watermarkContentPresenter != null && !string.IsNullOrEmpty(this.Text)) { this.watermarkContentPresenter.Visibility = Visibility.Collapsed; } if (this.textBox != null) { this.textBox.Text = this.initialisedText; this.UpdateTextBoxItems(); } }
/// <summary> /// Creates a textblock with the correct styles applied. /// </summary> /// <returns>A textblock with the correct style.</returns> private TextBlock CreateTextBlock() { if (this.decoratorItemsControl == null) { DependencyObject currentObject = VisualTreeHelper.GetParent(this); while (currentObject != null) { if (currentObject.GetType() == typeof(DecoratorItemsControl)) { this.decoratorItemsControl = (DecoratorItemsControl)currentObject; break; } currentObject = VisualTreeHelper.GetParent(currentObject); } } if (this.decoratorItemsControl != null) { return(new TextBlock() { FontFamily = this.decoratorItemsControl.FontFamily, FontSize = this.decoratorItemsControl.FontSize, FontStyle = this.decoratorItemsControl.FontStyle, FontWeight = this.decoratorItemsControl.FontWeight, TextWrapping = TextWrapping.Wrap, HorizontalAlignment = HorizontalAlignment.Left }); } else { return(new TextBlock() { TextWrapping = TextWrapping.Wrap, HorizontalAlignment = HorizontalAlignment.Left }); } }
/// <summary> /// Updates the existing container styles. /// </summary> /// <param name="sender">The DecoratorItemsControl.</param> /// <param name="args">Dependency Property Changed Event Args.</param> private static void DecoratorItemContainerStyle_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs args) { DecoratorItemsControl itemsControl = (DecoratorItemsControl)sender; itemsControl.UpdateItemContainerStyle(); }
/// <summary> /// Creates a textblock with the correct styles applied. /// </summary> /// <returns>A textblock with the correct style.</returns> private TextBlock CreateTextBlock() { if (this.decoratorItemsControl == null) { DependencyObject currentObject = VisualTreeHelper.GetParent(this); while (currentObject != null) { if (currentObject.GetType() == typeof(DecoratorItemsControl)) { this.decoratorItemsControl = (DecoratorItemsControl)currentObject; break; } currentObject = VisualTreeHelper.GetParent(currentObject); } } if (this.decoratorItemsControl != null) { return new TextBlock() { FontFamily = this.decoratorItemsControl.FontFamily, FontSize = this.decoratorItemsControl.FontSize, FontStyle = this.decoratorItemsControl.FontStyle, FontWeight = this.decoratorItemsControl.FontWeight, TextWrapping = TextWrapping.Wrap, HorizontalAlignment = HorizontalAlignment.Left }; } else { return new TextBlock() { TextWrapping = TextWrapping.Wrap, HorizontalAlignment = HorizontalAlignment.Left }; } }