I want to add masking to a WPF date control. I saw that DatePickerTextBox could not be expanded further.
So, I decided to add interactive behavior to it. For this, I used the following code:
Masked date picker class:
public class MaskedDatePicker : DatePicker { }
and I created an attached behavior as shown below:
public class DatePickerTextBoxInputMaskBehavior : Behavior<DatePickerTextBox> { }
Now in the templates I have bound the behavior:
<DatePickerTextBox x:Name="PART_TextBox" Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Focusable="{TemplateBinding Focusable}" Foreground="{TemplateBinding Foreground}"> <i:Interaction.Behaviors> <cleanPoc:DatePickerTextBoxInputMaskBehavior /> </i:Interaction.Behaviors> </DatePickerTextBox>
Now every time I open a calendar from a datepicker application, it freezes because the text changed in DatePickerTextBoxInputMaskBehavior starts recursively. Any idea how to handle this?
user3974502
source share