Help with converting to PropertyControl

Jun 8, 2012 at 4:52 PM

Using PropertyEditor I set up a editing template for one of my own types using

<pt:PropertyEditor.Editors>
       <pt:TypeEditor EditedType="{x:Type mylib:Range}" EditorTemplate="{StaticResource RangeEditor}" />
</pt:PropertyEditor.Editors>

How do I do this for PropertyControl ? I can see in the examples that a Viewmodel may be used but can I just append a specific type editor to PropertyControl as I did with PropertyEditor. And if so how?

I tried overriding CreateControl in LocalPropertyControlFactory but this does not seem to be called (or at least the debug.Print statement I included does not appear on output).

I have

<pt:PropertyControl
   CategoryControlType="Expander"    
    x:Name="wpfPropertyControl1">
   <pt:PropertyControl.Factories>
   <local:LocalPropertyControlFactory />
     </pt:PropertyControl.Factories>

</pt:PropertyControl>

with

public class LocalPropertyControlFactory : IPropertyControlFactory
    {
        public FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options)
        {
            Debug.WriteLine("Instance is {0}",pi.Instance.ToString());
            return null;
        }
    }

and see an expected message on the output window

System.Windows.Data Error: 1 : Cannot create default converter to perform 'two-way' conversions between types 'ProfileGenerator.Range' and 'System.String'. Consider using Converter property of Binding. BindingExpression:Path=XRange; DataItem='Profile' (HashCode=8059334); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')

but no sign of the Debug output. I am going to add code for the control when I am sure that LocalPropertyControlFactory is being called. I am not sure I understand what is going on here so any help would be much appreciated.

Alan

Coordinator
Jun 15, 2012 at 10:57 PM
Edited Jun 15, 2012 at 10:58 PM

hi Alan!

sorry, I see the PropertyControl.Factories property was not implemented. I have now decided to delete it, it was not really needed. You should use the PropertyControl.PropertyControlFactory property instead. Also, create a sub-class of the "DefaultPropertyControlFactory". 

I added a new example "CustomFactoryDemo" that shows usage of both the PropertyControlFactory and PropertyItemFactory. I added a Range type in the example model.

I have not found a way to use templates in the PropertyControl, since the bindings are different for each property.

You could also create a custom TypeConverter (to/from string) for your Range type, then the standard TextBox will be able to edit the values!

I see there is a need to document these 'advanced' topics, I hope to get time for that later this year.