[英]Xceed property grid - [RefreshProperties(RefreshProperties.All)] attribute not working
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.
我正在为组合框属性使用[RefreshProperties(RefreshProperties.All)]。 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 如果用户选择“ DeleteDirectory”,则应显示以下属性,而其他属性则应隐藏
[AppliesTo(Op.DeleteDirectory)]
public bool Recursive { get; set; }
My Xaml: 我的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. 这适用于Winform属性网格,但不适用于Xceed wpf属性网格。 Need help if I am missing any property to set.
如果我缺少要设置的任何属性,则需要帮助。
I have the same problem with modifying the ReadOnly
attribute of a property. 我在修改属性的
ReadOnly
属性时遇到同样的问题。 WinForm PropertyGrid works, Xceed PropertyGrid doesn't. WinForm PropertyGrid有效,Xceed PropertyGrid不起作用。 May be the paid Plus version would work.
可能是付费Plus版本可以使用。 It has a
DependsOn
attribute. 它具有
DependsOn
属性。
I solved it using the PropertyGrid's PropertyValueChanged
event. 我使用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]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.