所以我有这个Storyboard
:
<Storyboard x:Key="animate">
<DoubleAnimation BeginTime="0:0:0" Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:2.0"/>
</Storyboard>
我的绑定value
:
public bool IsFound
{
get { return _isFound; }
set
{
_isFound= value;
NotifyPropertyChanged();
}
}
还有我的Grid
得到这个Storyboard
:
<Grid name="myGrid">
....
<Grid>
if(IsFound)
{
Storyboard storyboard = Resources["animate"] as Storyboard;
if (storyboard != null)
storyboard.Begin(myGrid);
}
所以我正在寻找纯XAML
的东西,而不是在后面的代码中检查此IsFound
。
答案 0 :(得分:1)
您可以使用DataTrigger:
<Style TargetType="Grid" x:Key="MyAnimatedGrid">
<Style.Triggers>
<DataTrigger Binding="{Binding IsFound}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard StoryBoard="{StaticResource animate}" />
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>