2013-05-15 3 views
0

textBox1에 대해 DataTrigger을 구현하고 싶습니다. textBox1 안에 Text이 "ABC"이면 "일치하는 데이터!"라고 표시하려고합니다. 다른 TextBox에 말하면, textBox2. 이 xaml 코드 아래에 있지만 작동하지 않는 작성했습니다. 오류 메시지 아래에 있습니다. 이것에 대한DataTriggers : 작동 방식

'Text' member is not valid because it does not have a qualifying type name 

XAML 코드는 다음과 같습니다 바인딩에 문제가

<Window x:Class="ControlTemplateDemo.Animation" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    Title="Animation" Height="300" Width="607"> 
<Grid> 
    <Border Background="White"> 
     <StackPanel Margin="30" HorizontalAlignment="Left" Width="500" Height="209"> 
      <TextBox Name="textBox1">           
       <TextBox.Triggers> 
        <DataTrigger Binding="{Binding Path=Text}"> 
         <DataTrigger.Value> 
          <sys:String>ABC</sys:String> 
         </DataTrigger.Value> 
         <Setter TargetName="textBox2" Property="Text" Value="Data matched!"/>        
        </DataTrigger> 
       </TextBox.Triggers> 
      </TextBox>     
      <TextBox Name="textBox2">      
      </TextBox> 
     </StackPanel> 
    </Border> 
</Grid> 

</Window> 

있습니까?

덕분에, 인 Hemant

답변

2

당신은 같은 초 TextBox

무엇인가에 대한 Style에서 DataTrigger을 제공해야합니다

<StackPanel> 
    <TextBox x:Name="inputBox" /> 
    <TextBox Margin="0 25 0 0"> 
    <TextBox.Style> 
     <Style TargetType="{x:Type TextBox}"> 
     <Setter Property="Text" 
       Value="No Match Found" /> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding ElementName=inputBox, 
              Path=Text}" 
         Value="ABC"> 
      <Setter Property="Text" 
        Value="Match Found" /> 
      </DataTrigger> 
     </Style.Triggers> 
     </Style> 
    </TextBox.Style> 
    </TextBox> 
</StackPanel> 

TextBox.Triggers

DataTrigger를 지원하지 않습니다. 나는 EventTriggers에 대해서만 설명서가 있다고 생각하는데,

쪽 노트에, 나는 보통 목표로 끝나는 요소에서 바인딩을 할 수있다. 이렇게하면 최소한 개인적으로 디버깅하는 것이 더 쉽습니다. TextBox에 잘못된 정보가있는 경우 즉시 내 xaml 파일의 모든 바인딩보다 어떤 요소에 내 바인딩이 잘못되어 내 TextBox을 업데이트하는지 확인합니다.