Is it possible to style/template a TextBox so that input fills its value from right to left? My question is not related to the Arabic writing - I'm trying to make a textbox for a currency field, so that when a user types '12' - the value becomes '0.12'. C#/WPF/MVVM project here
Use FlowDirection.
<TextBox Text="" FlowDirection="RightToLeft" />
For more info check this link Bidirectional Features in WPF Overview
Did you try HorizontalContentAlignment? It should work for you.
<TextBox HorizontalContentAlignment="Right" Text="6999958"></TextBox>
For converting the value '12' to '0.12', please use a converter like
<TextBox HorizontalContentAlignment="Right" Text="6999958" Converter={Binding CurrencyConverter}></TextBox>
And here goes the converter code :
public class CurrencyConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var intValue = int.Parse(value.ToString());
var result = 0;
try
{
result = intValue/100;
}
catch (Exception)
{
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With