2012-06-08 5 views
1

내 페이지를 깜박 거리게 만드는 데이터 트리거를 만들고 싶습니다 (투명에서 빨간색으로). 그래서 나는 내 viewmodel 내에서 부울 플래그를 수신하는 DataTrigger를 만들었습니다. 이 플래그는 사용자가 상기시켜야 할 때마다 나타냅니다. 이 경우 내 페이지가 투명에서 빨간색으로 깜박입니다.DataTrigger가 실행되지 않는 것 같습니다.

데이터 트리거를 올바른 방식으로 구현 했음에도 불구하고 내 앱은 아무 것도하지 않습니다. 오류가없고 깜박이지 않습니다. 그래서 놓친 게있을 것입니다.

<Style x:Key="ReminderPage" TargetType="{x:Type ViewTemplates:TpApplicationBarView}" BasedOn="{StaticResource TpApplicationBarViewStyle}"> 
    <Style.Triggers> 

     <!-- Reminder animation, when the time comes to remind the user --> 
     <DataTrigger Binding="{Binding IndicateReminderAnimation}" Value="True"> 
      <DataTrigger.EnterActions> 
       <BeginStoryboard> 
        <Storyboard x:Name="Blink"> 
         <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
             AutoReverse="True" 
             From="Transparent" 
             To="Red" 
             Duration="0:0:1" 
             RepeatBehavior="Forever"> 
         </ColorAnimation > 
        </Storyboard> 
       </BeginStoryboard> 
      </DataTrigger.EnterActions> 
     </DataTrigger> 

     <DataTrigger Binding="{Binding IndicateReminderAnimation}" Value="False"> 
      <DataTrigger.EnterActions> 
       <BeginStoryboard> 
        <Storyboard> 
         <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
             AutoReverse="False" 
             To="Transparent" 
             Duration="0:0:1"> 
         </ColorAnimation > 
        </Storyboard> 
       </BeginStoryboard> 
      </DataTrigger.EnterActions> 
     </DataTrigger> 
    </Style.Triggers> 
</Style> 

그래서 내가 잘못 했습니까?

업데이트 :

System.Windows.Media.Animation Warning: 6 : Unable to perform action because 
the specified Storyboard was never applied to this object for interactive control.;   
Action='Stop'; Storyboard='System.Windows.Media.Animation.Storyboard'; 
Storyboard.HashCode='61356140'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; 
TargetElement='System.Windows.Media.Animation.Storyboard'; TargetElement.HashCode='61356140'; 
TargetElement.Type='System.Windows.Media.Animation.Storyboard' 

갱신 2 : 내가 출력 창에 다음과 같은 메시지가 볼 수 arround를 인터넷 검색 후를 나는 그것이 UI 스레드에 문제가 있음을, 발견했다. 그래서 나는 바인딩 된 속성을 설정할 때마다 디스패처 호출을 만들었습니다. 그러나이 트릭을 사용하더라도 색상 애니메이션이 없습니다. 그러나 출력 창의 오류가 사라진 것 같습니다. 그래서 애니메이션을 수정하는 방법에 대한 더 많은 아이디어를 찾고 있습니다.

업데이트 3 : 페이지의 배경색을 설정하는 것이 일반적인 문제인 것처럼 보입니다. 그러나 그것은 정말로 이상합니다. Page는 NavigationFrame에 배치됩니다. 탐색 프레임의 배경색을 설정하면 응용 프로그램의 색상이 변경되지만 아무런 애니메이션이 없어도 페이지의 배경색을 설정해도 아무 것도 바뀌지 않습니다.

+2

'IndicateReminderAnimation' 속성에 대해'INotifyPropertyChanged'를 구현 했습니까? 런타임 중에 VS에서 출력 창을 확인 했습니까? 바인딩 오류가 있습니까? – nemesv

+0

hm. INotifyPropertyChanged를 구현했습니다. 그러나 출력을보고 다음 오류가 발생했습니다. System.Windows.Media.Animation 경고 : 6 : 지정된 스토리 보드가 대화 형 제어를 위해이 개체에 적용되지 않았기 때문에 작업을 수행 할 수 없습니다. 액션 = '멈춤'; Storyboard = 'System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode = '61356140'; Storyboard.Type = 'System.Windows.Media.Animation.Storyboard'; TargetElement = 'System.Windows.Media.Animation.Storyboard'; TargetElement.HashCode = '61356140'; TargetElement.Type = 'System.Windows.Media.Animation.Storyboard ' – BitKFu

답변

0

버그를 발견했거나 더 나은 두 버그를 발견했습니다.

1.) 탐색 프레임 내에있는 페이지의 배경색을 변경할 수없는 것처럼 보입니다.

그래서 먼저 MainWindow를 자체 (WPF 창 클래스)

2) 작동하지 않았다 데이터 트리거가 포함 된 스타일에 바인딩 및 이벤트를 이동했다. 인터넷 검색을 수행 한 후 검색 대상 솔루션을 찾았습니다.

<Storyboard x:Key="RemindUser" > 
    <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
        AutoReverse="True" 
        From="Transparent" 
        To="{StaticResource WinAccentBackgroundColor}" 
        Duration="0:0:1" 
        RepeatBehavior="Forever"> 
    </ColorAnimation > 
</Storyboard> 

<Storyboard x:Key="StopRemindUser"> 
    <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
        AutoReverse="True" 
        To="Transparent" 
        Duration="0:0:1"> 
    </ColorAnimation > 
</Storyboard> 

<Style x:Key="ReminderWindow" TargetType="{x:Type Metro:SnappedTransparentWindow}" BasedOn="{StaticResource TransparentWindow}"> 
    <Style.Triggers> 

     <!-- Reminder animation, when the time comes to remind the user --> 
     <DataTrigger Binding="{Binding IndicateReminderAnimation}" Value="True"> 
      <DataTrigger.EnterActions> 
       <BeginStoryboard Storyboard="{StaticResource RemindUser}"/> 
      </DataTrigger.EnterActions> 
      <DataTrigger.ExitActions> 
       <BeginStoryboard Storyboard="{StaticResource StopRemindUser}"/> 
      </DataTrigger.ExitActions> 
     </DataTrigger> 
    </Style.Triggers> 
</Style> 

열쇠는 바인딩과 스토리 보드를 다른 부분으로 분리하는 것이 었습니다.

+0

@ BitKFu : 두 번째 요점을 설명 할 수 있습니까? 그게 무슨 뜻인지 분명하지 않습니까? 나는 이것이 페이지와 관련된 문제라고 생각합니다. 저는 여러분의 스타일을 창문으로 시도하고 있었고 제대로 작동했습니다. – akjoshi

+0

예, 알고 있습니다. 정말 이상합니다. 귀하의 의견 때문에, 나는 스스로 테스트 프로젝트를 만들었고 실제로, 페이지의 배경색도 설정할 수있었습니다. 내 응용 프로그램에서 작동하지 않습니다 ... 그래서 이상한 ... 시간이 더 있다면, 나는 또한 그 미스터리에 대한 대답을 알고 싶기 때문에 그것을 재현하려고 노력할 것입니다. – BitKFu

0

난 당신이 애니메이션 대상이 같은 설정해야합니다 생각 -

Storyboard.TargetName="yourWindowName" 

당신은 이미 체크 가지고 있지만, 올바른 목적이 TpApplicationBarView의의 DataContext로 설정되어 있는지 확인 할 수있다을 (가진 IndicateReminderAnimation 속성) .

+0

죄송합니다. 그러나 스타일 내에서 targetname을 지정할 수 없습니다. – BitKFu

관련 문제