Okay, well here's what I have working so far, but it's quite obvious that this is a hack at the very least.
Template:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:editors="http://schemas.actiprosoftware.com/winfx/xaml/editors"
xmlns:sample="clr-namespace:MyProjectsNamespace"
xmlns:propgrid="http://schemas.actiprosoftware.com/winfx/xaml/propgrid">
<DataTemplate x:Key="{x:Static sample:PropertyEditors.DynamicEnumTemplateKey}">
<ComboBox x:Name="editBox" Margin="0" Padding="0" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" BorderThickness="0" Background="Transparent"
SelectedItem="{Binding Value, RelativeSource={RelativeSource
AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=OneWayToSource,
ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True,
UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Value, RelativeSource={RelativeSource
AncestorType={x:Type propgrid:IPropertyDataAccessor}}, ValidatesOnExceptions=True,
ValidatesOnDataErrors=True, NotifyOnValidationError=True,
UpdateSourceTrigger=PropertyChanged}"
/>
</DataTemplate>
</ResourceDictionary>
PropertyEditor Code:
namespace MyProjectsNamespace
{
public static class PropertyEditors
{
// Value Template Resource Keys
private static ComponentResourceKey dynamicEnumTemplateKey;
public static ResourceKey DynamicEnumTemplateKey
{
get
{
if (dynamicEnumTemplateKey == null)
dynamicEnumTemplateKey =
new ComponentResourceKey(typeof(PropertyEditors), "DynamicEnumTemplate");
return dynamicEnumTemplateKey;
}
}
}
public class DynamicEnumPropertyEditor : PropertyEditor
{
public override DataTemplate ValueTemplate
{
get { return null; }
set { /* No-op */ }
}
public override object ValueTemplateKey
{
get { return PropertyEditors.DynamicEnumTemplateKey; }
}
public override DataTemplateSelector ValueTemplateSelector
{
get { return null; }
set { Console.WriteLine("TEST: " + value); /* No-op */ }
}
}
}
In Use:
public class TestObject
{
private string selectedSponsor = "None";
private string[] sponsorList = new string[] { "None", "Sponsor1", "Sponsor2", "Sponsor3" };
public string GetSponsor()
{
return selectedSponsor;
}
[Category("Sponsor")]
[Description("Select the sponsor for this item.")]
[Editor(typeof(DynamicEnumPropertyEditor), typeof(PropertyEditor))]
[TypeConverter(typeof(StringConverter))]
public object Sponsor
{
//The get provides the whole list to the object which is fed into the combobox
get { return sponsorList; }
//The set is one way (to source) bound to the object and gets the selected item.
set { selectedSponsor = (value ?? "").ToString(); }
//The whole thing is an object because it gets and sets different types.
//The TypeConverter is set to StringConverter to prevent the array from having expanded properties.
}
}
As you can see, it's a total hack as of now.
What does work:
► It does display correctly
► It does not have expanded items underneath it for each array value because of the TypeConverter being set to StringConverter
► It does return the proper value to the Setter of the source object.
What does not work:
► With this method, I cannot dynamically set the source object in code.
► This method doesn't allow me to create a single object that does all of this, instead I am using multiple variables to get the proper outcome
I suspect that I need to create a custom IPropertyDataAccessor to do this properly from a single object like I displayed in the original post. But this is where I am currently at. Any pointers to move forward will be appriciated.