我有两个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;
}
}
帮助赞赏!谢谢!