2

I am working on wpf legacy code and found strange issue. We are using custom control TimePicker inherits from Textbox. We used dependency property to validate time and mask with default value like _ : _. It is working fine with English digits/fonts, but if I change language input to Chinese (in windows 10) then it behave differently.

class TimePicker : TextBox 

    static TimePicker()
    {
        // to receive coercion callback when Text property got changed
        InputMaskProperty = DependencyProperty.Register("InputMask",
           typeof(string), typeof(TimePicker),
           new FrameworkPropertyMetadata(InputMask_Changed,
           new CoerceValueCallback(OnCoerceValueChange)));
    }

Expected behavior in general that when user hit keyboard then below event get raised :

protected override void OnPreviewTextInput(TextCompositionEventArgs e)

And here only I am setting some value like this.Text = "some value" in above event than it is invoking below event which is actually CoerceValueCallback:

  private static object OnCoerceValueChange(DependencyObject obj, object value)

All is fine if I use English font, it called in above mentioned manner, but if I change culture / Input language in windows 10 to chinese simplified than it is directly setting the this.Text value and than calling OnPreviewKeyDown , OnPreviewTextInput. Any suggestion please how to make logic independent of culture specific.

Xaml code is like:

           <External:TimePicker x:Name="StartTimePicker" InputMask="ii:ii" Grid.Row="1" Grid.Column="7" HorizontalAlignment="Left" 
                    Validation.Error="StartTimePickerError" Text="{Binding Path=StartTime, ValidatesOnDataErrors=True, 
                    UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" Width="50"
                    ToolTip="{Binding RelativeSource ={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}">
            </External:TimePicker>

It also throws System.ExecutionEngineException if it encounters e.Key under event OnPreviewKeyDown(KeyEventArgs e)

Subodh
  • 75
  • 1
  • 10

0 Answers0