2013-01-17 79 views
1

我試圖根據屬性的值使網格「淡入」或「淡出」。該屬性正在調用,但動畫似乎並未影響網格。我的網格和觸發器的樣子:使用DataTrigger觸發動畫並綁定

<Grid Background="White" 
     Opacity="0"> 
    <Grid.Style> 
    <Style TargetType="Grid"> 
     <Style.Triggers> 
     <DataTrigger Binding="{Binding IsWaiting}" 
        Value="False"> 
      <DataTrigger.EnterActions> 
      <BeginStoryboard Name="pickIn"> 
       <Storyboard> 
       <DoubleAnimation Storyboard.TargetProperty="Opacity" 
           From="0" 
           To="1" 
           Duration="0:0:0.8" /> 
       </Storyboard> 
      </BeginStoryboard> 
      </DataTrigger.EnterActions> 
      <DataTrigger.ExitActions> 
      <StopStoryboard BeginStoryboardName="pickIn" /> 
      </DataTrigger.ExitActions> 
     </DataTrigger> 
     <DataTrigger Binding="{Binding IsWaiting}" 
        Value="True"> 
      <DataTrigger.EnterActions> 
      <BeginStoryboard Name="pickOut"> 
       <Storyboard> 
       <DoubleAnimation Storyboard.TargetProperty="Opacity" 
           From="1" 
           To="0" 
           Duration="0:0:0.8" /> 
       </Storyboard> 
      </BeginStoryboard> 
      </DataTrigger.EnterActions> 
      <DataTrigger.ExitActions> 
      <StopStoryboard BeginStoryboardName="pickOut" /> 
      </DataTrigger.ExitActions> 
     </DataTrigger> 
     </Style.Triggers> 
    </Style> 
    </Grid.Style> 
    <Grid.Triggers> 
    <EventTrigger RoutedEvent="Loaded"> 
     <BeginStoryboard> 
     <Storyboard> 
      <DoubleAnimation Storyboard.TargetProperty="Opacity" 
          From="0" 
          To="1" 
          Duration="0:0:0.8" /> 
     </Storyboard> 
     </BeginStoryboard> 
    </EventTrigger> 
    </Grid.Triggers> 
    <!-- etc --> 
</Grid> 

IsWaiting財產的樣子:

public bool IsWaiting{ 
    get { return _isWaiting; } 
    set { 
    _isWaiting = value; 
    OnPropertyChanged("IsWaiting"); 
    } 
} 

有輸出日誌時屬性的變化沒有綁定錯誤。我究竟做錯了什麼?

+0

看看這個帖子http://stackoverflow.com/questions/1013817/wpf-fade-animation?rq=1 –

+1

我只是複製粘貼你的代碼,它工作正常,我改變的唯一的事情是持續時間,所以我可以看到它褪色(我用'0:0:5') –

+1

@ sa_ddam213 Jeez,你說得對。原來有另一個動畫干擾了它。我會更新我的代碼以包含干擾代碼。如果您想發佈回覆,我可以將其標記爲答案。 '''部分需要被刪除。 – Daniel

回答

2

<Grid.Triggers>取代您的<Style.Triggers>,您可以在網格加載或將其設置爲true bu默認值時將IsWaiting設置爲true來替換<Grid.Triggers>動畫。