Thank you - that worked. It also looks likes it works adding PropertyEditors in C#. I tried an experiment and modified the range of the Int32PropertyEditor dynamically directly from code and it seemed to work to dynamically change the range without creating custom editor. Is this a bad idea?
Here's my test code
using ActiproSoftware.Windows;
using ActiproSoftware.Windows.Controls.Editors.Interop.Grids.PropertyEditors;
using ActiproSoftware.Windows.Controls.Grids.PropertyData;
using System.ComponentModel;
using System.Windows;
namespace WpfApp3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var pe = new Int32PropertyEditor() { PropertyName = "Value", Minimum = 100, Maximum = 255 };
theGrid.PropertyEditors.Add(pe);
DataContext = new Data()
{
Test = pe,
Name = "this is a name",
Value = 234,
Option = Options.No
};
}
}
public enum Options { Yes, No, Maybe };
public class Data : ObservableObjectBase, IPropertyOwner
{
public Int32PropertyEditor Test { get; set; }
[Category("General")]
[DisplayName("A Name")]
public string Name { get; set; }
[Category("General")]
[DisplayName("Some Value")]
public int Value { get; set; }
Options option;
[Category("General")]
[DisplayName("Some Options")]
public Options Option
{
get => option;
set
{
if(option != value)
{
option = value;
if (option == Options.Maybe) Test.Minimum = 0;
else Test.Minimum = 50;
}
}
}
bool showIt;
public bool ShowIt
{
get => showIt;
set
{
if( showIt != value)
{
showIt = value;
NotifyPropertyChanged("ShowIt");
NotifyPropertyChanged("It");
}
}
}
int it;
public int It
{
get => it;
set
{
if( it != value)
{
it = value;
this.NotifyPropertyChanged("It");
}
}
}
public bool GetPropertyVisibility(string name)
{
if (name == "It") return ShowIt;
return true;
}
}
interface IPropertyOwner
{
bool GetPropertyVisibility(string name);
}
public class CustomPropertyModel : PropertyDescriptorPropertyModel
{
public CustomPropertyModel(object target, PropertyDescriptor propertyDescriptor) : base(target, propertyDescriptor) { }
public bool IsVisible
{
get
{
if (this.Target is IPropertyOwner owner) return owner.GetPropertyVisibility(this.Name);
return true;
}
}
bool updating = false;
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
// Call the base method
base.OnPropertyChanged(e);
if (!updating)
{
updating = true;
this.NotifyPropertyChanged("IsVisible");
updating = false;
}
}
}
public class CustomDataFactory : TypeDescriptorFactory
{
protected override IPropertyModel CreatePropertyModel(object target, PropertyDescriptor propertyDescriptor, IDataFactoryRequest request)
{
var prop = new CustomPropertyModel(target, propertyDescriptor);
return prop;
}
}
}