0

I am creating a self composing UserControl in WPF.

I have an attribute I adorn the properties of my entity with that instructs my SelfComposingUserControl what to do.

If I want a property to be edited by a specific UI Control I pass this in my attribute.

In my attribute, I'm really not sure how to pass which property on the UI Control I would like bound to my entity property.

Can anybody help?

Here is a stripped down version of my UIEditableAttribute:

public class UIEditableAttribute : Attribute
{
    /// <summary>
    /// UIControl to edit the property
    /// </summary>
    public Type UIControl { get; set; }

    /// <summary>
    /// UIControl dependency property that binds to the property
    /// </summary>
    public DependencyProperty UIControlValueProperty { get; set; }
}

And here is an example of a property using the attribute

    private int _numberOfRows;
    [UIEditable(DisplayGroup = "B", UIControl = typeof(RadNumericUpDown), UIControlValueProperty = RadNumericUpDown.ValueProperty)]
    public int NumberOfRows
    {
        get { return _numberOfRows; }
        set { CheckPropertyChanged(ref _numberOfRows, value); }
    }

In the SelfComposingUserControl, I have got around this by using a switch statement on the type of UIControl that binds the property to the correct dependency property. I would however like to specify at the property level.

Many thanks in advance.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Lance
  • 251
  • 5
  • 13
  • This sounds very like the functionality implemented by the PropertyGrid control in the XCeed Extended WPF Toolkit, to define Custom Editors. Look at [the description](https://github.com/xceedsoftware/wpftoolkit/wiki/PropertyGrid) after the header "Custom Editors with Attributes". Their solution is to mandate that the editors implement an interface ITypeEditor. – Phil Jollans Aug 09 '19 at 20:47

1 Answers1

0

The answer is to pass the UIControlValueProperty as a string i.e. "ValueProperty" in the attribute, then get this useful function;

Get Dependency Property By Name

to get the dependency property from the type or object.

Lance
  • 251
  • 5
  • 13