I want to create custom text box (which will contain simple watermark/hint text) and I some reached problems with dependecy properties. My custom class inherits from TextBox class and consist of two files (.xaml .cs) C# code file is very simple:
public partial class HintTextBox : TextBox
{
public string HintText
{
get { return (string)GetValue(HintTextProperty); }
set { SetValue(HintTextProperty, value); }
}
public static readonly DependencyProperty HintTextProperty =
DependencyProperty.Register(
"HintText",
typeof(string),
typeof(HintTextBox),
new FrameworkPropertyMetadata(string.Empty));
}
.xaml file contains code which show/hide watermark
<local:HintTextBox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Ribes.Client.GUI"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<local:HintTextBox.Style>
<Style TargetType="{x:Type local:HintTextBox}">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
<VisualBrush.Visual>
<Label Content="{Binding HintText, ElementName=local:HintTextBox}" Foreground="LightGray" />
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers><!-- triggers changing content of control --></Style.Triggers>
</Style>
</local:HintTextBox.Style>
I'm trying to obtain simple usage of my HintTextBox:
<local:HintTextBox HintText="hint text"></local:HintTextBox>
And it's does not work. After create brakepoint on line :
SetValue(HintTextProperty, value);
code is never reached. Inherited properties (Text,Background) of TextBox works fine:
<local:HintTextBox Text="example text" Background="Yellow"></local:HintTextBox>
We can see correct yellow TextBox with 'example text' inside.
Have anybody idea what can be wrong with my DP ?
Regars NQ