let's say I have a several textboxes with with dependency to model that has IsDecimalAllowed property.
So some of this textboxes have IsDecimalAllowed = true and some of them false.
So I need to determine which of this fields can take non-integer values and use this flag into TextBox_TextChanged event to remove extra characters or add input restriction.
Now I implemented it with Tag value of TextBox but it seems not the best desigion I could made..
XAML:
<TextBox Text="{Binding DataValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource DoubleConverter}}"
InputScope="Number"
IsEnabled="{Binding IsEnabled}"
TextChanged="TextBox_TextChanged"
Tag="{Binding IsDecimalAllowed}">
<!-- it would be nice to have custom property here -->
<!-- for example IsDecimalAllowed="{Binding IsDecimalAllowed}" -->
TextBox_IsChanged:
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textBox = sender as TextBox;
if (textBox == null)
throw new InvalidCastException();
bool? isAllowDecimalTag = textBox.Tag as bool?;
if (isAllowDecimalTag == null)
return;
if (isAllowDecimalTag == false)
{
// some logic here
}
else if (isAllowDecimalTag == true)
{
// some logic here
}
}
I tried to find something and stumbled upon DependencyProperty. Is it able to implement it via DependencyObject or somehow?
Thank you in advance for any help.