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");
}
}
有輸出日誌時屬性的變化沒有綁定錯誤。我究竟做錯了什麼?
看看這個帖子http://stackoverflow.com/questions/1013817/wpf-fade-animation?rq=1 –
我只是複製粘貼你的代碼,它工作正常,我改變的唯一的事情是持續時間,所以我可以看到它褪色(我用'0:0:5') –
@ sa_ddam213 Jeez,你說得對。原來有另一個動畫干擾了它。我會更新我的代碼以包含干擾代碼。如果您想發佈回覆,我可以將其標記爲答案。 '''部分需要被刪除。 –
Daniel