bodong1987 / Avalonia.PropertyGrid

A property edit control in Avalonia like DevExpress's PropertyGridControl.
https://www.cnblogs.com/bodong
MIT License
184 stars 19 forks source link

ShowStyle="Alphabetic" is not Alphabetic. #29

Closed ykarpeev closed 5 months ago

ykarpeev commented 5 months ago

I noticed that ShowStyle="Alphabetic" does not sort alphabetically but by their order in the viewmodel.

If I have this view model:

    public partial class MainWindowViewModel : ViewModelBase
    {
        [DisplayName("B")]
        public string PropertyB { get; set; }

        [DisplayName("A")]
        public string PropertyA { get; set; }
    }

It is sorted like this: image

I changed BuildAlphabeticPropertiesView in PropertyGrid.axaml.cs to sort alphabetically by displayname to test:

   protected virtual void BuildAlphabeticPropertiesView(object target, ReferencePath referencePath)
        {
            propertiesGrid.ColumnDefinitions.Clear();
            propertiesGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
            propertiesGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));

            var sortedProperties = ViewModel.AllProperties.OrderBy(x => x.DisplayName);
            BuildPropertiesCellEdit(target, referencePath, sortedProperties, null, propertiesGrid, CellInfoCache);
        }

Not sorting alphabetically is actually what I am trying to do so the functionality works well for me - but I am seeing if I can sort by some explicit attribute like [Display(Order = 0)] rather than just the sequence of the property.

I figured out one way to sorder by order property here:

https://github.com/ykarpeev/Avalonia.PropertyGrid/commit/ef972f603b3c799a902bbb4f5d49d333494dd803?diff=split&w=1

bodong1987 commented 5 months ago

Revision: d1fec45aa1990d98aa729cdb0b52e269679b17c9 Author: bodong Date: 2024/6/3 9:57:37 Message: fix : https://github.com/bodong1987/Avalonia.PropertyGrid/issues/29


Modified: Avalonia.PropertyGrid/Controls/PropertyGrid.axaml.cs Modified: Avalonia.PropertyGrid/ViewModels/PropertyGridViewModel.cs