Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBox input right to left

Tags:

wpf

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

like image 790
Alexey Titov Avatar asked Jun 09 '26 02:06

Alexey Titov


2 Answers

Use FlowDirection.

<TextBox Text="" FlowDirection="RightToLeft" />

For more info check this link Bidirectional Features in WPF Overview

like image 158
Hidamax Avatar answered Jun 10 '26 19:06

Hidamax


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();
    }
}
like image 20
ViVi Avatar answered Jun 10 '26 19:06

ViVi