【问题标题】:WPF: pure XAML when lunch Storyboard base of binding conditionWPF:午餐时纯 XAML 绑定条件的情节提要基础
【发布时间】:2018-12-18 23:34:07
【问题描述】:

所以我有这个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

【问题讨论】:

    标签: wpf storyboard


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2021-09-22
      • 2015-03-06
      • 2010-12-11
      • 1970-01-01
      • 2016-12-09
      • 1970-01-01
      • 2011-01-12
      • 2013-02-24
      相关资源
      最近更新 更多