1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
public class CustomControlText : Control
{
static CustomControlText()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControlText), new FrameworkPropertyMetadata(typeof(CustomControlText)));
}
//-------------------------------------------------------------------------------
#region Text
//-------------------------------------------------------------------------------
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
//-------------------------------------------------------------------------------
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(
"Text",
typeof(string),
typeof(CustomControlText),
new FrameworkPropertyMetadata(String.Empty,
FrameworkPropertyMetadataOptions.Journal | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
new PropertyChangedCallback(TextChanged),
new CoerceValueCallback(TextCoerce),
true,
UpdateSourceTrigger.LostFocus
));
//-------------------------------------------------------------------------------
public static Object TextCoerce(DependencyObject d, Object baseValue)
{
CustomControlText _CustomControlText = d as CustomControlText;
// insert you code here
return baseValue; // replace this line if necessary
}
//-------------------------------------------------------------------------------
public static void TextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CustomControlText _CustomControlText = d as CustomControlText;
// déactivated only used for simple type - int, double ... -)
//string _Text = (string)e.NewValue;
string _Text = e.NewValue as string;
// insert you code here
}
//-------------------------------------------------------------------------------
#endregion
//-------------------------------------------------------------------------------
} |
Partager