I'm using a beavior in a TextBox control to filter input via a regex. For this I added a dependency property to get the regex value. When I set directly in xaml the value, It works properly but when I'm trying to pass it with a bind property, the regex value is not setted in the dependency property:
public class TextBoxInputRegExBehaviour : Behavior<TextBox>
{
public static readonly DependencyProperty RegularExpressionProperty =
DependencyProperty.Register("RegularExpression", typeof(string), typeof(TextBoxInputRegExBehaviour), new FrameworkPropertyMetadata(".*"));
public string RegularExpression
{
get { return (string)GetValue(RegularExpressionProperty);
set { SetValue(RegularExpressionProperty, value); }
}
...
}
When using this format, no problem:
<TextBox Text="{Binding MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Style="{StaticResource ValidableTextBox}">
<i:Interaction.Behaviors>
<behaviours:TextBoxInputRegExBehaviour RegularExpression="[0-9.]+$" />
</i:Interaction.Behaviors>
</TextBox>
But not working with binding:
<TextBox Text="{Binding MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Style="{StaticResource ValidableTextBox}">
<i:Interaction.Behaviors>
<behaviours:TextBoxInputRegExBehaviour RegularExpression="{Binding MyRegExString}" />
</i:Interaction.Behaviors>
</TextBox>
What did I wrong?