Reputation: 6547
I have a DataGrid
which is binded to a collection of models. My model has a string property called Position
which is of type string, but contains an integer value.
My problem is, when sorting this column values get sorted as 1, 10, 2
instead of 1, 2, 10
.
Is there anyway to handle this MVVM style without handling the Sorting
event of the DataGrid
in code-behind?
Bear in mind I cannot change the type of the property.
Upvotes: 2
Views: 5124
Reputation: 6881
If you don't want to do it in the code-behind, I think you will want a custom sort behavior, like shown in this SO post...
https://stackoverflow.com/a/18218963/1246574
I know you said you don't want to break MVVM so you don't want to handle a sort event in the code-behind. Even so, in case anyone else wants to know how to do it that way, this SO post shows how...
https://stackoverflow.com/a/2130557/1246574
Upvotes: 5