두 DataGrid 열 사이에 유효성 종속성을 만들려고합니다.열 사이의 데이터 격자 유효성 검사 종속성을 만들 수 있습니다
첫 번째 열은 드롭 다운 상자입니다. (DataGridTemplateColumn) 두 번째는 텍스트 열입니다. (DataGridTextColumn)
동일한 행의 DataGrid 텍스트 열 셀의 유효성 검사를 강제하려면 코드의 드롭 다운 상자 이벤트에서 시도하고 있습니다.
도움 주셔서 감사합니다.
<data:DataGridTemplateColumn Header="Type" >
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource TypeListContainer}, Path=TypeLists}" Loaded="TypeBoxLoaded" DropDownClosed="TypeBoxChanged">
</ComboBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTextColumn Header="Rule" Binding="{Binding RuleWrapper, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" x:Name="RuleCol" />
여기에 몇 가지주의해야 할 재산
public string RuleWrapper
{
get
{
return this.Rule;
}
set
{
//Required
if (value == null || value == string.Empty)
{
throw new ValidationException("Rule is required");
}
//Match regular expression if type is channel
Regex reg = new Regex(@"^(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)$");
if (Type == "channel" && !reg.IsMatch(value))
throw new ValidationException("Channel not matching the right format");
//Match range if type is trunk
int intValue = -1;
//Match if is a number
if (int.TryParse(value, out intValue))
{
//Match if number is in the range
if (intValue < 0 || intValue > 134217727)
throw new ValidationException("Trunk value must be between 0 and 134317727");
}
else
throw new ValidationException("Trunk value must a an integer");
this.Rule = value;
}
}
ComboBox 컨트롤의 목적은 무엇입니까? 선택한 값도 유효해야합니까?귀하의 예제에서 당신은'RuleWrapper = RuleWrapper'를 호출하여 유효성 검사를 강제 할 수 있습니다,하지만 그것이 당신이 필요로하는 것인지 확신하지 못합니다. – vorrtex
combox 상자를 선택하면 규칙에 대해 다른 유효성 검사가 트리거됩니다. 그래서 RuleWrapper = RuleWrapper를 사용하여 코드의 유효성을 강제로 확인한 후에 ValidationException이 발생하지만 DataGrid에 올바르게 표시되도록 처리하는 방법을 모르겠습니다. – Stainedart
IDataErrorInfo를 사용하면 유효성 검사를 강제하는 방법을 알고 있습니다. INotifyDataErrorInfo 인터페이스. 이러한 유효성 검사가 인터페이스에 의해 수행되도록이 유효성 검사를 완전히 다시 작성하면 어떻게 생각하십니까? 그러면 모든 유효성 검사 코드를 다시 작성해야합니다. – vorrtex