Loading...
Loading...
Compare original and translation side by side
Syncfusion.PropertyGrid.WPFSyncfusion.SfInput.WPFSyncfusion.SfShared.WPFSyncfusion.Shared.WPFSyncfusion.Tools.WPFxmlns:syncfusion="http://schemas.syncfusion.com/wpf"Syncfusion.PropertyGrid.WPFSyncfusion.SfInput.WPFSyncfusion.SfShared.WPFSyncfusion.Shared.WPFSyncfusion.Tools.WPFxmlns:syncfusion="http://schemas.syncfusion.com/wpf"PropertyGrid
├── SearchBox (optional) - Filter properties by name
├── Sort/Group Buttons - Toggle between sorted and categorized views
├── Property List
│ ├── Property Name Column
│ └── Value Editor Column (context-sensitive editors)
└── Description Panel (optional) - Shows property descriptionPropertyGrid
├── SearchBox(可选)- 按名称筛选属性
├── 排序/分组按钮 - 在排序视图和分类视图之间切换
├── 属性列表
│ ├── 属性名称列
│ └── 值编辑器列(上下文敏感型编辑器)
└── 描述面板(可选)- 显示属性描述<Window x:Class="PropertyGridSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
<Grid>
<syncfusion:PropertyGrid Name="propertyGrid1"
SelectedObject="{Binding SelectedEmployee}"
Width="400" Height="500">
<syncfusion:PropertyGrid.DataContext>
<local:ViewModel/>
</syncfusion:PropertyGrid.DataContext>
</syncfusion:PropertyGrid>
</Grid>
</Window>// Employee class to be explored in PropertyGrid
public class Employee : INotifyPropertyChanged
{
private string name;
public string Name
{
get => name;
set { name = value; OnPropertyChanged(nameof(Name)); }
}
[Display(Name = "Employee ID")]
[Description("Unique identifier for the employee")]
public string ID { get; set; }
[Category("Personal Info")]
[DisplayName("Date of Birth")]
public DateTime DOB { get; set; }
[Category("Personal Info")]
[Range(18, 65)]
public int Age { get; set; }
[Browsable(false)] // Hide this property
public string InternalCode { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
// ViewModel
public class ViewModel
{
public object SelectedEmployee { get; set; }
public ViewModel()
{
SelectedEmployee = new Employee
{
Name = "Johnson",
Age = 25,
ID = "EMP001",
DOB = new DateTime(1999, 5, 15)
};
}
}<Window x:Class="PropertyGridSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
<Grid>
<syncfusion:PropertyGrid Name="propertyGrid1"
SelectedObject="{Binding SelectedEmployee}"
Width="400" Height="500">
<syncfusion:PropertyGrid.DataContext>
<local:ViewModel/>
</syncfusion:PropertyGrid.DataContext>
</syncfusion:PropertyGrid>
</Grid>
</Window>// 要在PropertyGrid中展示的Employee类
public class Employee : INotifyPropertyChanged
{
private string name;
public string Name
{
get => name;
set { name = value; OnPropertyChanged(nameof(Name)); }
}
[Display(Name = "Employee ID")]
[Description("Unique identifier for the employee")]
public string ID { get; set; }
[Category("Personal Info")]
[DisplayName("Date of Birth")]
public DateTime DOB { get; set; }
[Category("Personal Info")]
[Range(18, 65)]
public int Age { get; set; }
[Browsable(false)] // 隐藏此属性
public string InternalCode { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
// ViewModel
public class ViewModel
{
public object SelectedEmployee { get; set; }
public ViewModel()
{
SelectedEmployee = new Employee
{
Name = "Johnson",
Age = 25,
ID = "EMP001",
DOB = new DateTime(1999, 5, 15)
};
}
}// Custom Editor with email validation mask
public class EmailEditor : ITypeEditor
{
SfMaskedEdit maskedEdit;
public object Create(PropertyInfo propertyInfo)
{
maskedEdit = new SfMaskedEdit
{
MaskType = MaskType.RegEx,
Mask = "[A-Za-z0-9._%-]+@[A-Za-z0-9]+.[A-Za-z]{2,3}"
};
return maskedEdit;
}
public void Attach(PropertyViewItem property, PropertyItem info)
{
var binding = new Binding("Value")
{
Mode = BindingMode.TwoWay,
Source = info,
ValidatesOnExceptions = true,
ValidatesOnDataErrors = true
};
BindingOperations.SetBinding(maskedEdit, SfMaskedEdit.ValueProperty, binding);
}
public void Detach(PropertyViewItem property) { }
}
// Apply to property
public class Employee
{
[Editor("EmailID", typeof(EmailEditor))]
public string EmailID { get; set; }
}// 带邮箱验证掩码的自定义编辑器
public class EmailEditor : ITypeEditor
{
SfMaskedEdit maskedEdit;
public object Create(PropertyInfo propertyInfo)
{
maskedEdit = new SfMaskedEdit
{
MaskType = MaskType.RegEx,
Mask = "[A-Za-z0-9._%-]+@[A-Za-z0-9]+.[A-Za-z]{2,3}"
};
return maskedEdit;
}
public void Attach(PropertyViewItem property, PropertyItem info)
{
var binding = new Binding("Value")
{
Mode = BindingMode.TwoWay,
Source = info,
ValidatesOnExceptions = true,
ValidatesOnDataErrors = true
};
BindingOperations.SetBinding(maskedEdit, SfMaskedEdit.ValueProperty, binding);
}
public void Detach(PropertyViewItem property) { }
}
// 应用到属性
public class Employee
{
[Editor("EmailID", typeof(EmailEditor))]
public string EmailID { get; set; }
}public class Employee
{
[Category("Basic Info")]
public string Name { get; set; }
[Category("Basic Info")]
public string ID { get; set; }
[Category("Contact Details")]
public string Email { get; set; }
[Category("Contact Details")]
public string Phone { get; set; }
}<syncfusion:PropertyGrid SelectedObject="{Binding Employee}"
EnableGrouping="True"/>public class Employee
{
[Category("Basic Info")]
public string Name { get; set; }
[Category("Basic Info")]
public string ID { get; set; }
[Category("Contact Details")]
public string Email { get; set; }
[Category("Contact Details")]
public string Phone { get; set; }
}<syncfusion:PropertyGrid SelectedObject="{Binding Employee}"
EnableGrouping="True"/>public class Product
{
public string ProductName { get; set; }
// Collection property - automatically gets collection editor
public ObservableCollection<Customer> Customers { get; set; }
public Product()
{
Customers = new ObservableCollection<Customer>
{
new Customer { ID = 1, Name = "John" },
new Customer { ID = 2, Name = "Jane" }
};
}
}
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
}public class Product
{
public string ProductName { get; set; }
// 集合属性 - 自动获取集合编辑器
public ObservableCollection<Customer> Customers { get; set; }
public Product()
{
Customers = new ObservableCollection<Customer>
{
new Customer { ID = 1, Name = "John" },
new Customer { ID = 2, Name = "Jane" }
};
}
}
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
}private void PropertyGrid_AutoGeneratingPropertyGridItem(
object sender, AutoGeneratingPropertyGridItemEventArgs e)
{
// Hide specific properties
if (e.DisplayName == "InternalCode")
{
e.Cancel = true;
}
// Make property readonly
if (e.DisplayName == "ID")
{
e.ReadOnly = true;
}
// Change display name
if (e.DisplayName == "DOB")
{
e.DisplayName = "Date of Birth";
}
// Change category
if (e.DisplayName == "Age")
{
e.Category = "Personal Information";
}
}private void PropertyGrid_AutoGeneratingPropertyGridItem(
object sender, AutoGeneratingPropertyGridItemEventArgs e)
{
// 隐藏特定属性
if (e.DisplayName == "InternalCode")
{
e.Cancel = true;
}
// 将属性设为只读
if (e.DisplayName == "ID")
{
e.ReadOnly = true;
}
// 更改显示名称
if (e.DisplayName == "DOB")
{
e.DisplayName = "Date of Birth";
}
// 更改类别
if (e.DisplayName == "Age")
{
e.Category = "Personal Information";
}
}private void PropertyGrid_ValueChanged(object sender, ValueChangedEventArgs e)
{
var changedProperty = e.Property;
var oldValue = e.OldValue;
var newValue = e.NewValue;
// Log the change
Console.WriteLine($"{changedProperty.Name} changed from {oldValue} to {newValue}");
// React to specific property changes
if (changedProperty.Name == "Age")
{
// Validate or update related properties
}
}private void PropertyGrid_ValueChanged(object sender, ValueChangedEventArgs e)
{
var changedProperty = e.Property;
var oldValue = e.OldValue;
var newValue = e.NewValue;
// 记录变更
Console.WriteLine($"{changedProperty.Name} changed from {oldValue} to {newValue}");
// 响应特定属性的变更
if (changedProperty.Name == "Age")
{
// 验证或更新相关属性
}
}| Property | Type | Description |
|---|---|---|
| SelectedObject | object | The object whose properties are displayed |
| SelectedObjects | object[] | Multiple objects for common property editing |
| EnableGrouping | bool | Groups properties by category |
| SortDirection | ListSortDirection? | Sorts properties (Ascending, Descending, null) |
| PropertyExpandMode | PropertyExpandModes | FlatMode or NestedMode for complex objects |
| AutoGenerateItems | bool | Auto-generates property items (default: true) |
| 属性 | 类型 | 描述 |
|---|---|---|
| SelectedObject | object | 要显示其属性的对象 |
| SelectedObjects | object[] | 用于编辑公共属性的多个对象 |
| EnableGrouping | bool | 按类别对属性进行分组 |
| SortDirection | ListSortDirection? | 对属性进行排序(Ascending、Descending、null) |
| PropertyExpandMode | PropertyExpandModes | 复杂对象的显示模式(FlatMode或NestedMode) |
| AutoGenerateItems | bool | 自动生成属性项(默认值:true) |
| Property | Type | Description |
|---|---|---|
| SearchBoxVisibility | Visibility | Shows/hides the search box |
| ButtonPanelVisibility | Visibility | Shows/hides sort/group buttons |
| DescriptionPanelVisibility | Visibility | Shows/hides description panel |
| EnableToolTip | bool | Enables tooltips on property items |
| DisableAnimationOnObjectSelection | bool | Disables loading animation |
| 属性 | 类型 | 描述 |
|---|---|---|
| SearchBoxVisibility | Visibility | 显示/隐藏搜索框 |
| ButtonPanelVisibility | Visibility | 显示/隐藏排序/分组按钮 |
| DescriptionPanelVisibility | Visibility | 显示/隐藏描述面板 |
| EnableToolTip | bool | 启用属性项的工具提示 |
| DisableAnimationOnObjectSelection | bool | 禁用加载动画 |
| Property | Type | Description |
|---|---|---|
| HidePropertiesCollection | ObservableCollection<string> | Property names to hide |
| CustomEditorCollection | CustomEditorCollection | Custom editors for properties |
| Items | PropertyGridItemCollection | Manually defined property items |
| 属性 | 类型 | 描述 |
|---|---|---|
| HidePropertiesCollection | ObservableCollection<string> | 要隐藏的属性名称 |
| CustomEditorCollection | CustomEditorCollection | 属性的自定义编辑器 |
| Items | PropertyGridItemCollection | 手动定义的属性项 |
| Event | Description |
|---|---|
| AutoGeneratingPropertyGridItem | Fired when a property item is being created (can cancel or modify) |
| ValueChanged | Fired when a property value changes |
| SelectedPropertyItemChanged | Fired when the selected property changes |
| CollectionEditorOpening | Fired before collection editor opens (can cancel or set readonly) |
| 事件 | 描述 |
|---|---|
| AutoGeneratingPropertyGridItem | 创建属性项时触发(可取消或修改) |
| ValueChanged | 属性值变更时触发 |
| SelectedPropertyItemChanged | 选中的属性变更时触发 |
| CollectionEditorOpening | 集合编辑器打开前触发(可取消或设置只读) |
[Category][Description][DisplayName][Browsable(false)]ObservableCollection[Required][Range][Category][Description][DisplayName][Browsable(false)]ObservableCollection[Required][Range][Browsable]HidePropertiesCollectionAutoGenerateItems[Browsable]HidePropertiesCollectionAutoGenerateItemsCustomEditorCollectionITypeEditorCreateCustomEditorCollectionITypeEditorCreateIListCollectionEditorOpeningIListCollectionEditorOpening