how to override default dependency property metadata. for example ;Text property for textbox. i use this code
class UCTextBox : TextBox
{
public UCTextBox()
{
var defaultMetadata = TextBox.TextProperty.GetMetadata(typeof(TextBox));
TextBox.TextProperty.OverrideMetadata(typeof(UCTextBox),
new FrameworkPropertyMetadata(string.Empty,
FrameworkPropertyMetadataOptions.Journal |
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
defaultMetadata.PropertyChangedCallback,
new CoerceValueCallback(CoerceText)
));
}
private static object CoerceText(DependencyObject d, object value)
{
return value.ToString().Replace(",","");
}
but this In both runs(get,set)
No one can help me!!!:(((
Here is an example of a class derived from
TextBox
overriding the metadata for theText
property:Notice that the override is place in the
static
constructor, not the ordinary constructor.