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
180
Sorting in xamDataGrid with Converter
posted

I have a model that and a file size as Long property. I am displaying the size in the field and converting it to a human friendly file size (i.e. KB, MB, GB, etc.) instead of just a number. 

<igDp:Field Name="Size" Label="Size" Converter="{StaticResource diskSizeConvert}">
    <igDp:Field.Settings>
        <igDp:FieldSettings AllowEdit="False" EditAsType="sys:String"/>
    </igDp:Field.Settings>
</igDp:Field>

And Converter class:

[ValueConversion(typeof(long), typeof(string))]
    public class DiskSizeConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            return FileSystemUtils.ToHumanReadableDiskSize((long)value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            return value;
        }
    }

Field is read only (i.e. user is not allowed to edit it in the grid).

When sorting, the field is sorted by the text value (i.e. KB, MB, etc.) instead of the Long property. How can I get the sorting working properly?