2012-10-17 4 views
7

Expression Blend에서 다음 두 가지 상태를 정의했습니다. 나는 this 가이드를 따르려고 노력했지만 상태를 어떻게 언제 어떻게 바꿀지에 대한 정보가 필요할 때 매달려있는 것처럼 느껴집니다.WP7에서 VisualState를 변경하는 방법

enter image description here

내가 행동을 부착 오전 가이드에 따르면 내 UserControl에 (나는 "GotoState에"를 가정) - 그리고 내가 한 경우에도, 나는 것 - 불행하게도 나는 실제로 User Control을 생각하지 않는다 내 PortraitState과 내 LandscapeState에 비헤이비어를 첨부해야하나요?

LayoutRoot 요소에 GotoState을 첨부 할 수 있습니다. 그래서 나는 두 주 모두 내 행동을 첨부합니까? 어떤 도움이라도 대단히 감사하겠습니다.

* 편집 : xaml.cs 파일에서 놀고 있었고 프로그래밍 방식으로이 방법을 사용할 수 있다고 생각했습니다. 방향을 디버깅하고 변경할 때 스위치 케이스에 들어가 올바른 방향을 찾습니다. 그러나 주정부는 절대로 전환되지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

protected override void OnOrientationChanged(OrientationChangedEventArgs e) 
    { 
     switch (e.Orientation) 
     { 
      case PageOrientation.Landscape: 
       ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "LandscapeState", useTransitions: true); 
       break; 
      case PageOrientation.LandscapeRight: 
       ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "LandscapeState", useTransitions: true); 
       break; 
      case PageOrientation.LandscapeLeft: 
       ExtendedVisualStateManager.GoToElementState(root:LayoutRoot, stateName: "LandscapeState", useTransitions: true); 
       break; 
      case PageOrientation.Portrait: 
       ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true); 
       break; 
      case PageOrientation.PortraitUp: 
       ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true); 
       break; 
      case PageOrientation.PortraitDown: 
       ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true); 
       break; 
      default: 
       break; 
     } 
    } 

EDIT2 : 그것은 위가 GotoElementState false를 반환 것으로 보인다 시도하고, MSDN에 따라 때 ". 컨트롤이 성공적으로 새로운 상태로 전환하는 경우 true를 반환하고 그렇지 않으면 false"

이제 상태로 전환 될 수있는 원인은 무엇입니까?

답변

1

나는 다음을 수행하여 내 자신의 문제에 대한 해결책을 찾을 수 있었다.

ExtendedVisualStateManager.GotoElementState (UIElement, String, bool)를 사용하면 매우 잘 작동하지 않으므로 VisualStateManager.GotoState를 사용할 수있는 방법을 찾아야합니다.

는 단순히 같은 UserControl을 내에서 LayoutRoot를 포장하여 내 문제를 해결 : 내가 처음에 할 시도로

<UserControl x:Name="userControl"> 
    <Grid x:Name="LayoutRoot" Background="Transparent"> 
     <VisualStateManager.VisualStateGroups> 
    ... 
</UserControl> 

전환 상태는 지금 VisualStateManager.GotoState를 호출 간단하게 질문했다.

protected override void OnOrientationChanged(OrientationChangedEventArgs e) 
    { 
     base.OnOrientationChanged(e); 

     switch (e.Orientation) 
     { 
      case PageOrientation.Landscape: 
      case PageOrientation.LandscapeRight: 
      case PageOrientation.LandscapeLeft: 
       VisualStateManager.GoToState(control: userControl, 
                 stateName: "LandscapeState", 
                 useTransitions: true); 
       break; 
      case PageOrientation.Portrait: 
      case PageOrientation.PortraitUp: 
      case PageOrientation.PortraitDown: 
       VisualStateManager.GoToState(control: userControl, 
                 stateName: "PortraitState", 
                 useTransitions: true); 
       break; 
      default: 
       VisualStateManager.GoToState(control: userControl, 
            stateName: "PortraitState", 
            useTransitions: true); 
       break; 
     } 
    } 
1

변화 같은 WP7의 VisualState는 :

switch (e.Orientation) 
    { 
     case PageOrientation.Landscape: 

      VisualStateManager.GoToState(this, "LandscapeState", true); 

      break; 

     case PageOrientation.Portrait: 

      VisualStateManager.GoToElementState(this,"PortraitState", true); 

      break; 

     default: 

      break; 
    } 

관련 문제