超额属性网格- [RefreshProperties(RefreshProperties. all)]属性不工作
本文关键字:属性 RefreshProperties 工作 all 网格 | 更新日期: 2023-09-27 18:01:16
我有一个具有属性的类,基于选择组合框属性中的一个项目,其他属性将显示或隐藏。我使用[RefreshProperties(RefreshProperties. all)]作为组合框属性。类,该类绑定到属性grid:
[TypeConverter(typeof(PropertySubsetConverter<FileSystemOperation>))]
public class FileSystemOperation : IPropertySubsetObject
{
[Description("File system operations like Copy, Move, Delete & Check file.")]
[Category("Mandatory")]
[RefreshProperties(RefreshProperties.All)]
public Op Operation { get; set; }
public enum Op
{
/// <summary>
/// Copy file
/// </summary>
CopyFile,
/// <summary>
/// Move file
/// </summary>
MoveFile,
/// <summary>
/// Delete file
/// </summary>
DeleteFile,
/// <summary>
/// Delete directory
/// </summary>
DeleteDirectory,
/// <summary>
/// Check if file exists
/// </summary>
ExistFile
}
}
如果用户选择'DeleteDirectory',下面的属性应该显示,其他属性应该隐藏
[AppliesTo(Op.DeleteDirectory)]
public bool Recursive { get; set; }
我的Xaml :
<xctk:PropertyGrid x:Name="pk" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontWeight="ExtraBold" IsEnabled="{Binding PropertyGridIsEnabled}" SelectedObject="{Binding SelectedElement, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Background="#FF4A5D80" Foreground="White"/>
这适用于Winform属性网格,但不适用于Xceed wpf属性网格。需要帮助,如果我缺少任何属性设置。
我在修改属性的ReadOnly
属性时遇到了同样的问题。WinForm PropertyGrid工作,Xceed PropertyGrid没有。也许付费的Plus版本会起作用。它有一个DependsOn
属性。
我用PropertyGrid的PropertyValueChanged
事件解决了这个问题。
private void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
{
// get the descriptor of the changed property
PropertyDescriptor propDesc = ((PropertyItem)e.OriginalSource).PropertyDescriptor;
// try to get the RefreshPropertiesAttribute
RefreshPropertiesAttribute attr
= (RefreshPropertiesAttribute)propDesc.Attributes[typeof(RefreshPropertiesAttribute)];
// if the attribute exists and it is set to All
if (attr != null && attr.RefreshProperties == RefreshProperties.All)
{
// invoke PropertyGrid.UpdateContainerHelper
MethodInfo updateMethod = propertyGrid.GetType().GetMethod(
"UpdateContainerHelper", BindingFlags.NonPublic | BindingFlags.Instance);
updateMethod.Invoke(propertyGrid, new object[0]);
}
}