物业未启用设置触发与实施UITypeEditor的物业、UITypeEditor

2023-09-04 23:59:06 作者:平胸小美美

我有一个属性网格被点击的属性中的一个按钮时,某些字段填写。然而属性的设置不被触发。我不知道为什么。

I have a property grid that when a button is clicked for one of the properties, certain fields are filled in. However the property's set isn't being triggered. I do not know why.

 private OptoSigmaSettings dataToGet = new OptoSigmaSettings();

 [Editor(typeof(OptoSetupFormEditor), typeof(UITypeEditor))]
 [TypeConverter(typeof(ExpandableObjectConverter))]
 [Category("Setup")]
 public OptoSigmaSettings DataToGet
    {
        get { return dataToGet; }
        set
        {
            MessageBox.Show("Im here"); //This isnt happening.
            dataToGet = value; }
    }

 [Serializable]
public class OptoSigmaSettings
{
    private int duration = 0;
    private string direction = "Positive";
    private string functionToCall = "Home";

    public string FunctionToCall
    {
        get { return functionToCall; }
        set { functionToCall = value; }
    }

    public int Duration
    {
        get { return duration; }
        set { duration = value; }
    }
    public string Direction
    {
        get { return direction; }
        set { direction = value; }
    }
}

public class OptoSetupFormEditor : UITypeEditor
{
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }

    public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
    {
        IWindowsFormsEditorService service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
        OptoSigmaSettings opto = value as OptoSigmaSettings;

       if (service != null && opto != null)
       {
            using (OptoSigmaSetup form = new OptoSigmaSetup())
            {
                DialogResult result;
                result = service.ShowDialog(form);

                if (result == DialogResult.OK)
                {

                    opto.Direction  = form.Direction;
                    opto.FunctionToCall = form.FunctionToCall;
                    opto.Duration = form.Duration;

                }
            }
      }
        return opto; 
    }
}

您的帮助是AP preciated提前!

Your help is appreciated in advance!

这是使用标准的属性网格WinForms应用程序。

This is a WinForms app using the standard property grid.

推荐答案

下面是最终的解决方案:

Here was the solution in the end:

 public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
    {
        IWindowsFormsEditorService service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
        OptoSigmaLinearSettings opto = value as OptoSigmaLinearSettings;
        opto = (OptoSigmaLinearSettings)value;

        if (opto == null)
        {
            opto = new OptoSigmaLinearSettings();
        }

        if (service != null)
        {
            using (OptoSigmaLinearSetup form = new OptoSigmaLinearSetup(opto))
            {
                DialogResult result;
                result = service.ShowDialog(form);

                if (result == DialogResult.OK)
                {
                    opto = form.GeneralSettings;

                }
            }
        }
        return opto;
    }