public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (_textBox != null)
{
_textBox.TextChanged -= OnTextChanged;
}
if (ActionIconBorder != null)
{
ActionIconBorder.MouseLeftButtonDown -= OnActionIconTapped;
}
_rootGrid = GetTemplateChild(RootGridName) as Grid;
_textBox = GetTemplateChild(TextBoxName) as TextBox;
// Getting the foreground color to save for later.
_foregroundBrushEdit = Foreground;
// Getting template children for the hint text.
_hintContent = GetTemplateChild(HintContentName) as ContentControl;
_hintBorder = GetTemplateChild(HintBorderName) as Border;
if (_hintContent != null)
{
UpdateHintVisibility();
}
// Getting template children for the length indicator.
_lengthIndicator = GetTemplateChild(LengthIndicatorName) as TextBlock;
// Getting template child for the action icon
ActionIconBorder = GetTemplateChild(ActionIconBorderName) as Border;
if (_rootGrid != null && _lengthIndicator != null)
{
UpdateLengthIndicatorVisibility();
}
if (_textBox != null)
{
_textBox.TextChanged += OnTextChanged;
}
if (ActionIconBorder != null)
{
ActionIconBorder.MouseLeftButtonDown += OnActionIconTapped;
UpdateActionIconVisibility(); // Add back the padding if needed.
}
// Get template child for the action icon measurement text block.
_measurementTextBlock = GetTemplateChild(MeasurementTextBlockName) as TextBlock;
}