2014-04-03 1 views
0
에 대한

현재 내 비즈니스 오브젝트는 다음과 같습니다 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을 각 TextBoxTextBoxProperty1에 바인딩 4 텍스트 상자, TextBoxProperty2TextBoxProperty3 보유 , TextBoxProperty4. 내가 원하는 것은 값이 100에 이르지 않으면 StackPanel 주위에 빨간색 테두리가 표시되고 그 중 4 TextBoxes이 들어 있다는 것입니다. TextBoxStackPanel 대신에

<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은 다음과 같이 보일 것인가? BindingStackPanelOneWay이어야하며 원본을 수정할 수 없으므로 알아야합니다. 나는 그가 주로 텍스트 상자 등의 컨트롤에 개별 속성을 결합, 그 컨트롤에 유효성 검사 피드백을 제공하기위한 생각 -

+0

, StackPanel의 주위에 테두리 스타일을 위해 DataTrigger와 스타일을 만드는 모든 것을 즉시 삭제하고'ItemsControl'을 사용하십시오. –

답변

0

나는이 혼자 IDataErrorInfo 인터페이스를 사용하여 가능하면 확실하지 않다.

하나의 옵션은

public bool IsValid 
{ 
    get { return _isValid; } 
    set 
    { 
     if (_isValid != value) 
     { 
      _isValid = value; 
      OnPropertyChanged("IsValid"); 
     } 
    } 
} 

당신은 this[] 속성 내에서 참 또는 거짓이 속성 값을 설정하는 것 즉, (도 INPC을 구현해야합니다) 당신의 BO에 부울 속성을 노출하는 것입니다. 당신의 XAML에서

는 e.g.:-

<Style x:Key="BorderStyle" TargetType="Border"> 
    <Setter Property="BorderBrush" Value="White"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Style.Triggers> 
    <DataTrigger Binding="{Binding IsValid}" Value="False"> 
     <Setter Property="BorderBrush" Value="Red"/> 
    </DataTrigger> 
    </Style.Triggers> 
</Style> 

<Border Style="{StaticResource BorderStyle}"> 
    <StackPanel ..etc.. 
</Border> 
+0

이 사진을 찍으러 간다 –

+0

이것은 분명히 효과가 있지만, 아직 컨트롤 그룹 주위에 빨간색 테두리를 배치 할 수있는 가능성이 있는지 궁금합니다. StackPanel 일 필요는 없습니다. 다른 방법이 있습니까? –

관련 문제