2014-10-30 5 views
1

컨트롤 내용이 부모의 시각적 상태 변화에 반응 할 수 있습니까?내용의 상태 변화에 대한 반응 (Windows Phone)

다음 예제에서는 부모 컨트롤이 활성화되어있을 때 텍스트 블록의 전경을 빨간색으로 변경하고 싶습니다. 하지만이 코드는 작동하지 않습니다

<local:ExpandKeyButton x:Name="xpand" Height="30"> 
    <TextBlock x:Name="tb"> 
     Test 
     <VisualStateManager.VisualStateGroups> 
      <VisualStateGroup x:Name="General"> 
       <VisualState x:Name="Idle" /> 
       <VisualState x:Name="Active"> 
        <Storyboard> 
         <ObjectAnimationUsingKeyFrames Storyboard.TargetName="tb" Storyboard.TargetProperty="Foreground"> 
          <DiscreteObjectKeyFrame KeyTime="0" Value="Red" /> 
         </ObjectAnimationUsingKeyFrames> 
        </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 
    </TextBlock> 
</local:ExpandKeyButton> 
+0

스토리 보드 안쪽으로 타겟팅 할 수 있습니다 - 당신이 지역에 VisualStateGroups를 설정 한 경우 즉, : ExpandKeyButton, 그것은 여전히 ​​첫 번째 부분이 참 @bdimag TextBlock을 – bdimag

+0

을 수정할 수 있지만, 두 번째가 아닌, VisualStateGroups''때문에 거기에 무효가 될 것이다. VisualStateGroups는 ControlTemplate 또는 UserControl의 루트 요소에서만 정의 할 수 있습니다. – McGarnagle

답변

1

없음 - 시각적 상태는 소유의 ControlTemplate 외부 UI 요소 (직접) 시각적 상태 변경에 참여할 수 없다는 점에서, 컨트롤에 내부입니다. 나는 당신의 시나리오에서 몇 가지 가능성을 볼 수 있었다 :

  1. 을 "TB"TextBlock의는 "ExpandKeyButton"의 일반적인 기능의 경우, 그것은 시각적 상태 변경에 참여할 수 있도록하려면 ControlTemplate이 내부로 이동합니다.
  2. 또는 좀 더 느슨하게 결합 된 방식으로 TextBlock이 해당 상태에 바인딩 할 수있게하려면 속성 또는 이벤트를 "ExpandKeyButton"컨트롤에 추가하십시오. 예를 들어 ControlTemplate의 VisualStateManager 내에서 적절하게 설정할 수있는 "IsActive"종속성 속성을 추가 한 다음 TextBlock은 컨트롤이 활성화되었을 때 Foreground="{Binding ElementName=xpand,Path=IsActive,Converter={StaticResource ActiveToColorConverter}}"과 같은 바인딩을 사용하여 빨간색으로 만들 수 있습니다.
관련 문제