Сетка свойств Xceed — атрибут [RefreshProperties (RefreshProperties.All)] не работает

У меня есть класс со свойствами, основанными на выборе одного элемента в свойстве со списком, другие свойства будут отображаться или скрываться. Я использую [RefreshProperties(RefreshProperties.All)] для свойства поля со списком. Класс, привязанный к сетке свойств:

[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; }

Мой Ксамл:

<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. Нужна помощь, если мне не хватает какого-либо свойства для установки.


person Sanjoth    schedule 07.07.2015    source источник


Ответы (1)


У меня такая же проблема с изменением атрибута ReadOnly свойства. WinForm PropertyGrid работает, Xceed PropertyGrid — нет. Возможно, платная версия Plus будет работать. Он имеет атрибут DependsOn.

Я решил это, используя событие PropertyValueChanged PropertyGrid.

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]);
    }
}
person Jiří Skála    schedule 04.08.2015