2012-06-21 2 views
2

을 적용한 후 작동하지 않습니다 나는 내가 스타일을 추가 할 때까지 잘 작동하고 바인딩 다음 텍스트 상자를 가지고 : 나는 스타일을 텍스트 상자 채워집니다를 적용한 후는 바인딩이 더 이상 스타일

<TextBox Text="{Binding SelectedGroupPolicyTermSummary.ImportantInfo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
     HorizontalAlignment="Stretch" AcceptsReturn="True" 
     IsReadOnly="{Binding IsEditable, Converter={StaticResource InvertedBoolConverter}}" 
     Foreground="Red" TextWrapping="Wrap"> 
    <TextBox.Style> 
     <Style TargetType="{x:Type TextBox}"> 
      <Style.Triggers> 
       <Trigger Property="TextBox.IsReadOnly" Value="True"> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="{x:Type TextBox}"> 
           <TextBox Text="{TemplateBinding Text}" 
             VerticalAlignment="Bottom" 
             HorizontalAlignment="{TemplateBinding HorizontalAlignment}"      
             Style="{DynamicResource SelectableTextStyle}" 
             TextWrapping="{TemplateBinding TextWrapping}" 
             Foreground="{TemplateBinding Foreground}" 
             Width="{TemplateBinding Width}"/> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
        <Setter Property="Width" Value="Auto"/> 
       </Trigger> 
       <Trigger Property="TextBox.IsReadOnly" Value="False"> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="{x:Type TextBox}" > 
           <TextBox Text="{TemplateBinding Text}" 
             VerticalAlignment="Bottom" 
             HorizontalAlignment="{TemplateBinding HorizontalAlignment}"      
             Style="{DynamicResource TextBoxStyle}" 
             TextWrapping="{TemplateBinding TextWrapping}" 
             Foreground="{TemplateBinding Foreground}" 
             Width="{TemplateBinding Width}" 
             AcceptsReturn="{TemplateBinding AcceptsReturn}"> 
           </TextBox> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </TextBox.Style> 
</TextBox> 

을하지만, 어떤 변화가 전송되지 않습니다 다시 코드로. 어떤 아이디어?

답변

1

TemplateBinding 태그 확장은 기본적으로 다음과 같은 바인딩을 제공합니다

배경 색상과 이것 저것 같은 것들에 대한
{Binding RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay} 

, 잘 작동 것이다. 그러나 Text와 같은 무언가가 완전히 묶여지기를 원한다면 모드를 변경하고 긴 손을 사용해야합니다.

+0

대단히 감사합니다.이 문제가 해결되었습니다. :) – soaloa

1

제어 템플릿에서 바인딩을 양방향으로 설정해 보았습니까?

Binding NameOfProperty, Mode=TwoWay