Hi,
I'd like to use external sorting for my xamDataGrid (SortEvaluationModel = UseCollectionView). The documentation says external sorting is not supported for unbound fields. But how come external sorting is also not supported for AlternateBinding fields? For my AlternateBinding field, I have the AlternateBinding specified, so shouldn't the grid know the underlying property name to use to update the collection view?
Thanks,
Harold
Hello Harold,
In order to use external sorting with AlternateBinding in XamDataGrid you have to implement IComparable interface for the underlying property you want sort. I have attached a simple sample application where you can test this approach.
Let me know if you have any questions.
Sincerely,ZhivkoAssociate Software Developer
Hi Zhivko,
Sorry for the late reply. I tried your sample. It doesn't sort if I click on the column header. It only sorts if I click on your button. If I remove UseCollectionView, then sorting by column header works. Attached is a recording.
Hello Harlod,
Thank you for your feedback.
This is not a bug in XamDataGrid. It seems that the sorting process should be performed manually on filed which uses AlternateBinding. This is similar limitation like when using unbound fields.
Let me know if you need further assistance.
This workaround will probably work (but will require me to determine the existing ListSortDirection for the column). But is this a bug in the grid itself then? It works if I don't use External Sorting. And like you said, if I use External Sorting, then I have to use the code you provided. And the code you provided seems like something that can be done in the grid itself?
In order to sort the Field by label clicking in your scenario you can create a Style for LabelPresenter and handle the PreviewMouseLeftButtonDown event. This way in the event handler you can use the same code as from the button, for example:
<igDP:Field Name="InnerData" AlternateBinding="{Binding IData.USDPrice}" BindingType="UseAlternateBinding"> <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.LabelPresenterStyle> <Style TargetType="{x:Type igDP:LabelPresenter}"> <EventSetter Event="PreviewMouseLeftButtonDown" Handler="Lbl_PreviewMouseLeftButtonDown"/> </Style> </igDP:FieldSettings.LabelPresenterStyle> </igDP:FieldSettings> </igDP:Field.Settings></igDP:Field>
private void Lbl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e){ ICollectionView iCollectionView = (ICollectionView)this.Resources["sort_DataSource"]; iCollectionView.SortDescriptions.Clear(); iCollectionView.SortDescriptions.Add(new SortDescription("IData", ListSortDirection.Descending));}