SkillAgentSearch skills...

Avalonia.PropertyGrid

A property edit control in Avalonia like DevExpress's PropertyGridControl.

Install / Use

/learn @bodong1987/Avalonia.PropertyGrid
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Ask DeepWiki License

Avalonia.PropertyGrid

查看简体中文文档

This is a PropertyGrid implementation for Avalonia, you can use it in Avalonia Applications.
Its main features are:

  • Support automatic analysis of class's Properties like DevExpress's PropertyGridControl and display and edit
  • Support simultaneous editing of multiple objects in one PropertyGrid
  • Support custom types that implement the ICustomTypeDescriptor interface or TypeDescriptionProvider
  • Support custom property label controls
  • Support custom property cell edit
  • Support for additional property operation areas and their custom operations
  • Support collections editing, support for adding, inserting, deleting and clearing in the control
  • Support data verification
  • Support Built-in undo and redo framework
  • Support global ReadOnly setting
  • Support for automatically adjusting the visibility of properties based on conditions
  • Support path picking
  • Support three display modes: category-based, alphabetical sorting and builtin sorting
  • Support text filtering, regular expression filtering, and supports ignoring case settings
  • Support fast filtering by Category
  • Support data automatic reloading
  • Support automatic expansion of sub-objects
  • Support adjust the width of the property name and property value by drag the title
  • Support localization and realtime change language without restart
  • Support web

<a href="https://bodong1987.github.io/Avalonia.PropertyGrid/" target="_blank"> → View Online Demo</a>

How To Use

Use the source code of this project directly or use NUGET Packages:
https://www.nuget.org/packages/bodong.Avalonia.PropertyGrid
Then add PropertyGrid to your project, and bind the object to be displayed and edited to the DataContext property. If you want to bind multiple objects, just bind IEnumerable<T> directly.
An example of a minimal template project based on Avalonia:

// MainViewModel.cs
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using PropertyModels.ComponentModel;
using PropertyModels.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;

namespace AvaloniaApplication19.ViewModels;

public partial class MainViewModel : ViewModelBase
{
    [ObservableProperty]
    private string _greeting = "Welcome to Avalonia!";

    public SimpleObject Target { get; set; } = new SimpleObject();
}

public class SimpleObject : ReactiveObject
{
    public string Name { get; set; }
    public string Description { get; set; }

    [Trackable(0, 200)]
    [Range(100,150)]
    public int value { get; set; } = 100;

    [ConditionTarget]
    public bool isColorVisible { get; set; } = true;

    [PropertyVisibilityCondition(nameof(isColorVisible), true)]
    public Color color { get; set; } = Colors.AliceBlue;
}
<!-- MainView.axaml -->
<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:AvaloniaApplication19.ViewModels"
             xmlns:apc="clr-namespace:Avalonia.PropertyGrid.Controls;assembly=Avalonia.PropertyGrid"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="AvaloniaApplication19.Views.MainView"
             x:DataType="vm:MainViewModel">
  <Design.DataContext>
    <!-- This only sets the DataContext for the previewer in an IDE,
         to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
    <vm:MainViewModel />
  </Design.DataContext>

    <!-- bind your target object to DataContext -->
    <apc:PropertyGrid DataContext="{Binding Target}"></apc:PropertyGrid>
</UserControl>

How to Debug

Open Avalonia.PropertyGrid.sln, change config to Development, set Avalonia.PropertyGrid.Samples.Desktop as startup project, build and run it.

How to build Online Demo

run dotnet publish under Samples/Avalonia.PropertyGrid.Samples.Browser. This may end up taking several minutes.
Because of the bug in .net 8.0, you must use .net 9.0, otherwise you will encounter errors when running

Detail Description

Data Modeling

If you want to edit an object in PropertyGrid, you only need to directly set this object to the DataContext property of PropertyGrid, PropertyGrid will automatically analyze the properties that can support editing, and edit it with the corresponding CellEdit. At the same time, you can also use Attributes in System.ComponentModel, System.ComponentModel.DataAnnotations and PropertyModels.ComponentModel to mark these properties, so that these properties have some special characteristics.
Support but not limited to these:

System.ComponentModel.CategoryAttribute                     /* set property category */  
System.ComponentModel.BrowsableAttribute                    /* used to hide a property */    
System.ComponentModel.ReadOnlyAttribute                     /* make property readonly */  
System.ComponentModel.DisplayNameAttribute                  /* set friendly name */  
System.ComponentModel.DescriptionAttribute                  /* set long description text, When you point the mouse to the title, the corresponding Tooltip will appear. */  
System.ComponentModel.PasswordPropertyTextAttribute         /* mark text property is password */  
System.ComponentModel.DataAnnotations.EditableAttribute     /* mark list property can add/remove/clear elements */  
System.ComponentModel.DataAnnotations.RangeAttribute        /* set numeric range */  
System.Runtime.Serialization.IgnoreDataMemberAttribute      /* used to hide a property */  

In addition, there are other classes that can be supported in PropertyModels.ComponentModel and PropertyModels.ComponentModel.DataAnnotations, which can assist in describing class properties.
If you want to have some associations between your class properties, for example, some properties depend on other properties in implementation, then you can try to mark this dependency with PropertyModels.ComponentModel.DataAnnotations.DependsOnPropertyAttribute
but you need to inherit your class from PropertyModels.ComponentModel.ReactiveObject, otherwise you need to maintain this relationship by yourself, just trigger the PropertyChanged event of the target property when the dependent property changes.

PropertyModels.ComponentModel.FloatPrecisionAttribute                               /* set float percision */  
PropertyModels.ComponentModel.IntegerIncrementAttribute                             /* set integer increment by button*/  
PropertyModels.ComponentModel.WatermarkAttribute                                    /* set water mark, it is text hint*/  
PropertyModels.ComponentModel.MultilineTextAttribute                                /* make text edit can edit multi line text */  
PropertyModels.ComponentModel.ProgressAttribute                                     /* use progress bar to dipslay numeric value property, readonly */   
PropertyModels.ComponentModel.TrackableAttribute                                    /* use trackbar to edit numeric value property */  
PropertyModels.ComponentModel.EnumDisplayNameAttribute                              /* set friendly name for each enum vlaues */
PropertyModels.ComponentModel.EnumExcludeAttribute                                  /* Globally prohibit an enumerated field from appearing in the PropertyGrid. To configure it for a single property, you can use EnumPermitValuesAttribute or EnumProhibitValuesAttribute. */
PropertyModels.ComponentModel.AutoCollapseCategoriesAttribute                       /* By configuring this Attribute for a class, some Categories can be automatically collapsed in the initial state. */
PropertyModels.ComponentModel.DataAnnotations.DependsOnPropertyAttribute            /* mark this property is depends on the other property */  
PropertyModels.ComponentModel.DataAnnotations.FileNameValidationAttribute           /* mark this property is filename, so control will validate the string directly */  
PropertyModels.ComponentModel.DataAnnotations.PathBrowsableAttribute                /* mark string property is path, so it will provide a button to show path browser*/  
PropertyModels.ComponentModel.DataAnnotations.PropertyVisibilityConditionAttribute  /* set this property will auto refresh all visiblity when this proeprty value changed. */  
PropertyModels.ComponentModel.DataAnnotations.EnumPermitValuesAttribute<T>          /* For a single attribute configuration, force the allowed enumeration values ​​to be set */
PropertyModels.ComponentModel.DataAnnotations.EnumPermitNamesAttribute              /* based on enum names */
PropertyModels.ComponentModel.DataAnnotations.EnumProhibitValuesAttribute<T>        /* For individual attribute configurations, certain enumeration values ​​are forcibly prohibited from appearing in the candidate list */
PropertyModels.ComponentModel.DataAnnotations.EnumProhibitNamesAttribute            /* based on enum names */
PropertyModels.ComponentModel.DataAnnotations.IEnumValueAuthorizeAttribute          /* create your custom enum value filter based on this interface */
PropertyModels.ComponentModel.DataAnnotations.ImagePreviewModeAttribute             /* set image display mode */
PropertyModels.ComponentModel.DataAnnotations.FloatingNumberEqualToleranceAttribute /* You can use this tag to mark the tolerance value of a floating point number. When the change difference is less than this value, it is consid
View on GitHub
GitHub Stars322
CategoryDevelopment
Updated1mo ago
Forks39

Languages

C#

Security Score

95/100

Audited on Feb 24, 2026

No findings