Skip to content

Commit 03be1e1

Browse files
authored
Update README.md
1 parent c5e0cf8 commit 03be1e1

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
# How-to-set-desired-name-to-the-property-items-of-WPF-PropertyGrid-through-attributes
2-
In WPF applications, the PropertyGrid control is a powerful tool for displaying and editing properties of an object. However, by default, it shows the raw property names, which may not be user-friendly. To enhance the user experience, you can customize the display names of these properties using attributes. Syncfusion’s WPF PropertyGrid supports this customization through the use of the DisplayName and Name attributes.
3-
To set a desired name for a property item, you decorate the property in your model class with the DisplayName attribute from the System.ComponentModel namespace. This attribute overrides the default property name shown in the grid. For example:
1+
# How to Set Desired Names for Property Items in WPF PropertyGrid Using Attributes
2+
## Overview
3+
In WPF applications, the PropertyGrid control is a powerful tool for displaying and editing the properties of an object. However, by default, it shows raw property names, which may not be user-friendly. To improve the user experience, you can customize these display names using attributes.
44

5+
Syncfusion’s WPF PropertyGrid supports this customization through the use of the DisplayName and Name attributes.
6+
7+
## Customizing Property Names with DisplayName
8+
To set a custom name for a property item, decorate the property in your model class with the DisplayName attribute from the System.ComponentModel namespace. This attribute overrides the default property name shown in the grid.
9+
### Example
510
```csharp
611
using System.ComponentModel;
12+
713
public class Employee
814
{
9-
[DisplayNameAttribute("Employee Name")]
15+
[DisplayName("Employee Name")]
1016
public string Name { get; set; }
11-
[DisplayNameAttribute("Employee Age")]
17+
18+
[DisplayName("Employee Age")]
1219
public int Age { get; set; }
13-
[DisplayNameAttribute("Department")]
20+
21+
[DisplayName("Department")]
1422
public string Dept { get; set; }
1523
}
1624
```
25+
When this class is bound to the Syncfusion PropertyGrid, the grid will display:
26+
- Employee Name
27+
- Employee Age
28+
- Department
1729

18-
When this class is bound to the Syncfusion PropertyGrid, the grid will display "Employee Name", "Employee Age", and "Department" instead of the actual property names. This makes the UI more intuitive and readable for end users.
19-
The GitHub repository also demonstrates how to use the Name attribute to further customize the property labels. This is particularly useful when you want to localize or format property names differently depending on context.
20-
To implement this in your WPF project, ensure you have the Syncfusion WPF toolkit installed and reference the appropriate namespaces. Then, bind your object to the PropertyGrid and use attributes as shown above.
21-
This approach is clean, declarative, and maintains separation between your data model and UI presentation logic. It’s ideal for enterprise applications where clarity and customization are key.
30+
instead of the actual property names (Name, Age, Dept). This makes the UI more intuitive and readable for end users.

0 commit comments

Comments
 (0)