Reputation: 13
I have a class which has properties, based on selecting one item in the combobox property, other properties will be shown or hidden. I am using [RefreshProperties(RefreshProperties.All)] for the combobox property. Class which is bound to the property 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
}
}
if user select 'DeleteDirectory', below property should be shown and other properties should be hidden
[AppliesTo(Op.DeleteDirectory)]
public bool Recursive { get; set; }
My 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"/>
This works with Winform property grid, but not working with Xceed wpf property grid. Need help if I am missing any property to set.
Upvotes: 1
Views: 2020
Reputation: 680
I have the same problem with modifying the ReadOnly
attribute of a property. WinForm PropertyGrid works, Xceed PropertyGrid doesn't. May be the paid Plus version would work. It has a DependsOn
attribute.
I solved it using the PropertyGrid's PropertyValueChanged
event.
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]);
}
}
Upvotes: 3