Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
HorizontalContentAlignment to Left based on other field (column) value?
posted

Hi, I need to make some colmuns aligment to left based on the value of other column (language code e.g fi-FI, en-US, ar-SA -> right alignment).

Can I do it with binding or do I have to do it in code behind. I have a lot of rows (thousands) so I can not loop them in code behind or grid gets really slow?

Is it posible to do some kind of fast value converter? I know I can create style like

    <Style TargetType="{x:Type igEditors:XamDateTimeEditor}" >

        <Setter Property="HorizontalAlignment" Value="Left" />

        <Setter Property="HorizontalContentAlignment" Value="Left" />

    </Style>

 

Br,

Mauri Korhonen

Parents
  • 27093
    Verified Answer
    posted

    Hello Mauri, 

    I have been looking into your requirement and I can suggest you create a style for the XamDateTimeEditor with a Converter like this one:

     

    <local:StringToAlignmentConverter x:Key="con" />

           

    <Style TargetType="{x:Type igEditors:XamDateTimeEditor}">

        <Setter Property="HorizontalContentAlignment" Value="{Binding Path=Record.DataItem.Currency, ConverterCulture=en-US, RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Converter={StaticResource con}}" />

    </Style>

     

    where:

     

    Currency is the property containing the language code and

     

    public class StringToAlignmentConverter : IValueConverter

    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            if (value.ToString() == "ar-SA")

            {

                return HorizontalAlignment.Right;

            }

            else return HorizontalAlignment.Left;

        }

     

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            throw new NotImplementedException();

        }

    }

     

    Please let me know, if you require any further assistance on the matter.

Reply Children
No Data