Files
PropertyGrid/Examples/README.md
T
2026-08-10 14:46:18 +02:00

175 lines
4.6 KiB
Markdown

# PropertyGrid Examples
This directory contains example applications demonstrating the Avalonia PropertyGrid control.
## Available Examples
### 1. QuickStartExample
**Difficulty:** Beginner
**Focus:** Basic PropertyGrid usage
A simple example showing fundamental PropertyGrid features:
- Basic property types (string, int, decimal, bool, enum)
- Property categories
- Display names and descriptions
- Read-only properties
- DateTime properties
Perfect for getting started with PropertyGrid.
➡️ [View QuickStartExample](./QuickStartExample/)
**To run:**
```bash
dotnet run --project Examples/QuickStartExample/QuickStartExample.csproj
```
---
### 2. AdvancedExample ⭐ NEW
**Difficulty:** Advanced
**Focus:** Complex scenarios and enterprise features
A comprehensive example demonstrating advanced PropertyGrid capabilities:
- **Nested Objects** - DatabaseSettings and NetworkSettings
- **Data Validation** - Required, Range, StringLength attributes
- **INotifyPropertyChanged** - Real-time property updates
- **Computed Properties** - Dynamic read-only properties
- **7 Categories** - Organized configuration sections
- **25+ Properties** - Complex data model
- **Multiple Data Types** - TimeSpan, Guid, Lists, and more
- **Enum Descriptions** - User-friendly enum values
- **Password Fields** - Secure property display
Ideal for understanding production-level usage.
➡️ [View AdvancedExample](./AdvancedExample/)
**To run:**
```bash
dotnet run --project Examples/AdvancedExample/AdvancedExample.csproj
```
---
## Feature Comparison
| Feature | QuickStartExample | AdvancedExample |
|---------|-------------------|-----------------|
| **Properties** | ~10 | 25+ |
| **Categories** | 5 | 7 |
| **Nested Objects** | ❌ | ✅ (2 levels) |
| **Validation** | ❌ | ✅ (Required, Range, Length) |
| **Change Notifications** | ❌ | ✅ (INotifyPropertyChanged) |
| **Computed Properties** | ❌ | ✅ |
| **Password Fields** | ❌ | ✅ |
| **Collections** | ❌ | ✅ (List<string>) |
| **Metadata** | ❌ | ✅ (Guid, DateTime tracking) |
| **Data Types** | Basic | Extended (TimeSpan, Guid, etc.) |
| **Read-Only Properties** | ✅ (1) | ✅ (4) |
| **Descriptions** | ✅ | ✅ (Detailed) |
## Building All Examples
Build all examples at once:
```bash
dotnet build
```
Or build individually:
```bash
dotnet build Examples/QuickStartExample/QuickStartExample.csproj
dotnet build Examples/AdvancedExample/AdvancedExample.csproj
```
## Learning Path
1. **Start with QuickStartExample** - Learn the basics
- Property binding
- Categories and descriptions
- Basic data types
2. **Move to AdvancedExample** - Master advanced features
- Nested objects
- Validation
- Change notifications
- Complex data models
## Common Use Cases
### QuickStartExample is great for:
- Learning PropertyGrid basics
- Simple configuration editors
- Prototyping
- Single-level property editing
### AdvancedExample is great for:
- Enterprise applications
- Complex configuration management
- Settings dialogs with validation
- Hierarchical data editing
- Production-ready implementations
## Key PropertyGrid Features
Both examples demonstrate PropertyGrid's core capabilities:
### 🎨 Visual Features
- Category grouping with collapsible sections
- Property descriptions
- Search/filter functionality
- Modern Fluent UI design
### 🔧 Data Binding
- Two-way binding
- Multiple data types support
- Enum support with descriptions
- DateTime pickers
### 📋 Metadata Support
- `[Display]` - Names, descriptions, ordering
- `[Category]` - Logical grouping
- `[ReadOnly]` - Immutable properties
- `[Required]`, `[Range]`, `[StringLength]` - Validation
- `[PasswordPropertyText]` - Secure input
- `[EditorBrowsable]` - Advanced property grouping
### 🔄 Dynamic Features
- INotifyPropertyChanged support
- Real-time updates
- Computed properties
- Conditional property display
## Troubleshooting
### Build Issues
If you encounter build errors, ensure:
1. You're targeting .NET 10
2. Avalonia packages are version 12.1.0 or compatible
3. The solution includes the PropertyGrid project reference
### Runtime Issues
- Ensure `x:DataType` is set on the Window element for compiled bindings
- Verify all namespaces are correctly imported
- Check that model classes are public
## Contributing
Want to add more examples? Consider these ideas:
- Multi-object editing example
- Custom property editor example
- Dynamic property generation example
- Settings persistence example
- Theme customization example
## Support
For issues or questions about PropertyGrid:
1. Check the examples documentation
2. Review the PropertyGrid source code
3. Open an issue in the repository
---
**Happy coding with PropertyGrid!** 🚀