Show / Hide Table of Contents

Class NaturalSortComparer

Provides a string comparer wich is generally usable on all DataGridTextColumns.
The bound value must be a string.

Inheritance
object
MarkupExtension
NaturalSortComparer
Implements
IListSortComparer
IComparer
IComparer<object>
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Sartorius.SAF.Presentation.Markup
Assembly: Sartorius.SAF.Presentation.dll
Syntax
public class NaturalSortComparer : MarkupExtension, IListSortComparer, IComparer, IComparer<object>
Remarks

A list of strings: "a3", "a1", "a10", "a12", "a2", "a11", is sorted to: "a1", "a2", "a3", "a11", "a12", "a13". Traditionally the default string comparer sort it to: "a1", "a11", "a12", "a13", "a2", "a3"

Examples
<DataGrid SAF:AttachedProperties.AllowCustomSort="True">
    <DataGridTextColumn
            Header="Name"
            Binding="{Binding Name}" 
            SAF:AttachedProperties.CustomSortComparer="{SAF:NaturalSortComparer}"/>
</DataGrid>
<DataGrid SAF:AttachedProperties.AllowCustomSort="True">
    <DataGridTextColumn
            Header="Name"
            Binding="{Binding Unit.Name}" 
            SAF:AttachedProperties.CustomSortComparer="{SAF:NaturalSortComparer ColumnPropertyPath=Unit.Name}"/>
</DataGrid>

Constructors

View Source

NaturalSortComparer()

Initializes a new instance of the NaturalSortComparer class.

Declaration
public NaturalSortComparer()
View Source

NaturalSortComparer(string)

Initializes a new instance of the NaturalSortComparer class.

Declaration
public NaturalSortComparer(string columnPropertyPath)
Parameters
Type Name Description
string columnPropertyPath

The column property path.

Properties

View Source

ColumnPropertyPath

Gets or sets the column property path.

Declaration
public string ColumnPropertyPath { get; set; }
Property Value
Type Description
string
View Source

SortDirection

Gets or sets the sort direction.

Declaration
public ListSortDirection SortDirection { get; set; }
Property Value
Type Description
ListSortDirection

Methods

View Source

Compare(object, object)

Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.

Declaration
public virtual int Compare(object x, object y)
Parameters
Type Name Description
object x

The first object to compare.

object y

The second object to compare.

Returns
Type Description
int

A signed integer that indicates the relative values of x and y, as shown in the following table.Value Meaning Less than zero x is less than y. Zero x equals y. Greater than zero x is greater than y.

View Source

ProvideValue(IServiceProvider)

Provides the value.

Declaration
public override object ProvideValue(IServiceProvider serviceProvider)
Parameters
Type Name Description
IServiceProvider serviceProvider

The service provider.

Returns
Type Description
object
Overrides
MarkupExtension.ProvideValue(IServiceProvider)

Implements

IListSortComparer
IComparer
IComparer<T>

Extension Methods

CollectionExtensions.AddRange<T, TCollection>(TCollection, IEnumerable<T>)
SerializableObjectCloneExtension.Clone<T>(T)
  • View Source
Back to top Generated by DocFX