Create your base class and add an abstract Order
property to it that all sub classes must implement. Basically an integer which specifies their ordering.
You can also implement IComparable on your abstract class so that if compares objects based on their order property.
public abstract class WorkStatus : IComparable<WorkStatus> {
public abstract int Order { get; }
public int CompareTo(WorkStatus w)
{
if(w.Order < this.Order)
return 1;
if(w.Order > this.Order)
return -1;
return 0;
}
}
For each implementation, give them a different Order value.
public class FirstStatus : WorkStatus {
public override int Order {get { return 1; } }
}
public class SecondStatus : WorkStatus {
public override int Order { get { return 2; } }
}
Assuming your WPF grid is just applying a standard OrderBy query, then if should work as follows.
//LINQPAD SNIPPET
void Main()
{
List<WorkStatus> list = new List<WorkStatus>();
list.Add(new SecondStatus()); //out of order initially.
list.Add(new FirstStatus());
Console.WriteLine(list.OrderBy(x => x));
}