If you bind data to the TextBox.Text property, then another possible approach is to divert the logic from the control itself and place it in the converter. Your converter will look something like this ...
public class CommaReplaceConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value.ToString().Replace(",", ""); } }
And the data is tied to something like this ...
<TextBox Text="{Binding XXX, Converter={StaticResource CRC}" />
... where a static resource is defined as ...
<Window.Resources> <CommaReplaceConverter x:Key="CRC"/> </Windows.Resources>
source share