属性集未通过实现的UITypeEditor触发 [英] Property set isn't being triggered with a UITypeEditor implemented
本文介绍了属性集未通过实现的UITypeEditor触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个属性网格,当单击其中一个属性的按钮时,将填写某些字段.但是,不会触发该属性的设置.我不知道为什么.
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;
}
}
这是使用标准属性网格的WinForms应用.
This is a WinForms app using the standard property grid.
推荐答案
这是最后的解决方案:
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;
}
这篇关于属性集未通过实现的UITypeEditor触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文