1

我有两个Radio Buttons选项“新”和“现有”。我有一个 Validate 事件,Devexpress TextEdit如果TextEdit为空并在TextEdit. 场景:当我选择“新建”Radio button并将 TextEdit 留空并单击“保存”时,它会显示错误图标,这可以正常工作。但是,当我尝试切换到“现有”Radion button时,它不允许我切换/更改选项,而是由于验证而停留在“新”选项。但是,我想允许用户更改单选按钮的选项。

xml:

<RadioButton x:Name="rbNew" Content="New Mapping" Grid.Column="1" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" GroupName="Mappings" GotFocus="rbNew_GotFocus"/>
                    <dxe:TextEdit x:Name="txtMappingName" Grid.Column="1" Height="23" Margin="0,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" MaxLength="100" Grid.RowSpan="2" GotFocus="txtMappingName_GotFocus" Validate="txtMappingName_Validate" />
                    <RadioButton  x:Name="rbExisting" Content="Existing Mapping" Grid.Column="1" HorizontalAlignment="Left" Margin="0,6,0,0" VerticalAlignment="Top" Grid.Row="1" GroupName="Mappings"/>

xml.cs

  private void txtMappingName_Validate(object sender, DevExpress.Xpf.Editors.ValidationEventArgs e)
        {
            if ((bool)rbNew.IsChecked && string.IsNullOrEmpty(e.Value as string))
            {
                e.IsValid = false;
                e.ErrorContent = "Required";
                e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning;
            }
        }

帮助赞赏!谢谢!

4

1 回答 1

2

尝试检查属性InvalidValueBehavior是否为AllowLeaveEditor. 它应该如下所示:

<dxe:TextEdit x:Name="txtMappingName" Grid.Column="1" Height="23" Margin="0,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" MaxLength="100" Grid.RowSpan="2" GotFocus="txtMappingName_GotFocus" Validate="txtMappingName_Validate" InvalidValueBehavior="AllowLeaveEditor"/>

请让我知道这是否有效。

谢谢。

于 2013-08-19T05:42:02.183 回答