这是一个示例代码:
ButtonEdit be = new ButtonEdit()
{
DisplayFormatString = MyDisplayFrm,
MaskType = MaskType.RegEx,
Mask = "[-+]?([0-9]*[,.])?[0-9]+([eE][-+]?[0-9]+)?",
ValidateOnTextInput = false
};
Binding bindingValue = new Binding() { Source = PropItem, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay };
BindingOperations.SetBinding(be, ButtonEdit.EditValueProperty, bindingValue);
be.SetValue(Grid.ColumnProperty, 0);
be.Validate += be_Validate;
void be_Validate(object sender, ValidationEventArgs e)
{
if ((Convert.ToDouble(e.Value) <= MaxVal) && (Convert.ToDouble(e.Value) >= MinVal)) return;
MessageBoxResult mbr = MessageBox.Show("The value in not in the suggested range, do you want to continue?", "Min/Max Range validation", MessageBoxButton.YesNo);
if (mbr == MessageBoxResult.Yes)
{
return;
}
else
{
e.IsValid = false;
e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning;
e.ErrorContent = "Value is not in the suggested range. Please correct.";
}
}
当我将值更改为超出范围并更改焦点时,我会收到两次消息框;一个用于更改值,一个用于更改显示,因为编辑器将值(双倍)显示为适当的科学显示。
如何使 TextEdit(或在上面的 ButtonEdit 示例中)在更改显示时不检查验证?我的意思是它不应该放在首位,不是吗?由于 EditValue 属性没有改变,而只是显示(Text 属性)。
提前致谢 :)