현재 내 비즈니스 오브젝트는 다음과 같습니다 ErrorTemplate :는 StackPanel에
public class FooBar : IDataErrorInfo
{
public Int32 TextBoxProperty1 { get; set; }
public Int32 TextBoxProperty2 { get; set; }
public Int32 TextBoxProperty3 { get; set; }
public Int32 TextBoxProperty4 { get; set; }
public Int32 Total{ get; set; }
public override Boolean Validate()
{
if (Total < 100)
{
throw new Exception();
}
return true;
}
public string Error
{
get { throw new NotImplementedException(); }
}
public string this[String propertyName]
{
get
{
if (propertyName == "Total")
if (Validate())
return "Error";
return null;
}
}
}
을 지금 현재의 (a ResourceDictionary
에) 내 XAML 내 DataTemplate을 각 TextBox
이 TextBoxProperty1
에 바인딩 4 텍스트 상자, TextBoxProperty2
을 TextBoxProperty3
보유 , TextBoxProperty4
. 내가 원하는 것은 값이 100에 이르지 않으면 StackPanel 주위에 빨간색 테두리가 표시되고 그 중 4 TextBoxes
이 들어 있다는 것입니다. TextBox
내 StackPanel
대신에
<DataTemplate x:Key="MyTemplate">
<StackPanel Style="{StaticResource errorSPStyle}">
<StackPanel.DataContext>
<Binding Path="Parameter" Mode="TwoWay" ValidatesOnExceptions="True" NotifyOnValidationError="True" UpdateSourceTrigger="PropertyChanged" />
</StackPanel.DataContext>
<pres:TextBox Width="40">
<pres:TextBox.Text>
<Binding Path="Parameter.TextBoxProperty1" Mode="TwoWay" ValidatesOnExceptions="True" NotifyOnValidationError="True">
</Binding>
</pres:TextBox.Text>
</pres:TextBox>
<pres:TextBox Width="40">
<pres:TextBox.Text>
<Binding Path="Parameter.TextBoxProperty2" Mode="TwoWay" ValidatesOnExceptions="True" NotifyOnValidationError="True">
</Binding>
</pres:TextBox.Text>
</pres:TextBox>
<pres:TextBox Width="40">
<pres:TextBox.Text>
<Binding Path="Parameter.TextBoxProperty3" Mode="TwoWay" ValidatesOnExceptions="True" NotifyOnValidationError="True">
</Binding>
</pres:TextBox.Text>
</pres:TextBox>
<pres:TextBox Width="40">
<pres:TextBox.Text>
<Binding Path="Parameter.TextBoxProperty4" Mode="TwoWay" ValidatesOnExceptions="True" NotifyOnValidationError="True">
</Binding>
</pres:TextBox.Text>
</pres:TextBox>
나는 스타일을 얻을 수있는 방법을 적용 할 : 내 XAML은 다음과 같이 보일 것인가? Binding
은 StackPanel
에 OneWay
이어야하며 원본을 수정할 수 없으므로 알아야합니다. 나는 그가 주로 텍스트 상자 등의 컨트롤에 개별 속성을 결합, 그 컨트롤에 유효성 검사 피드백을 제공하기위한 생각 -
, StackPanel의 주위에 테두리 스타일을 위해 DataTrigger와 스타일을 만드는 모든 것을 즉시 삭제하고'ItemsControl'을 사용하십시오. –