Posted 4 September 2023, 3:02 pm EST
Hello.
In the previous PropertyGrid, the CustomComboBoxEditor was the following code:
public class CustomComboBoxEditor : C1ComboBox, ITypeEditorControl
{
// Events
public event PropertyChangedEventHandler ValueChanged;
// Fields
internal PropertyAttribute _selectedProperty;
private List<String> _itemsSource;
// Implementation
public CustomComboBoxEditor(List<String> itemsSource)
{
_itemsSource = itemsSource;
}
public ITypeEditorControl Create()
{
return new CustomComboBoxEditor(_itemsSource);
}
public void Attach(PropertyAttribute property)
{
EditorTypes editorType = EditorTypes.Align;
string selectedItemSelectedValueString;
//if (property.MemberName == "PictureScale")
//{
// editorType = EditorTypes.PictureScale;
// selectedItemSelectedValueString = (property.SelectedObject as FlexImage).PictureScale;
//}
//else
//{
editorType = EditorTypes.Align;
selectedItemSelectedValueString = (property.SelectedObject as FlexTextBox).Align;
//}
// Store current property
_selectedProperty = property;
// Set ComboBox
this.ItemsSource = _itemsSource;
this.SelectedItemChanged += CustomEditor_SelectedItemChanged;
// Bind Property to SelectedItem
Binding editorBinding = new Binding(property.MemberName);
editorBinding.Mode = BindingMode.TwoWay;
editorBinding.Source = property.SelectedObject;
this.SetBinding(C1ComboBox.SelectedItemProperty, editorBinding);
if (this.SelectedItem == null)
{
switch (editorType)
{
case EditorTypes.Align:
(property.SelectedObject as FlexTextBox).Align = selectedItemSelectedValueString;
break;
//case EditorTypes.PictureScale:
// (property.SelectedObject as FlexImage).PictureScale = selectedItemSelectedValueString;
// break;
default:
break;
}
}
}
public void Detach(PropertyAttribute property)
{
this.SelectedItemChanged -= CustomEditor_SelectedItemChanged;
}
public bool Supports(PropertyAttribute Property)
{
return Property.PropertyInfo.PropertyType == typeof(string);
}
private void CustomEditor_SelectedItemChanged(object sender, PropertyChangedEventArgs<object> e)
{
if (ValueChanged != null)
ValueChanged(this, new PropertyChangedEventArgs(_selectedProperty.MemberName));
}
private enum EditorTypes
{
Align,
//PictureScale
}
}
I have to port this.
Could you please create a CustomComboBox sample for PropertyGrid in 2023 v2?