1

我正在尝试根据属性的值使网格“淡入”或“淡出”。该属性被调用,但动画似乎没有影响网格。我的网格和触发器如下所示:

<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");
  }
}

属性更改时,输出日志中没有绑定错误。我究竟做错了什么?

4

1 回答 1

2

<Grid.Triggers>否决您<Style.Triggers>可以通过仅在网格加载时设置为 true 或将其设置为 true bu default来替换<Grid.Triggers>动画。IsWaiting

于 2013-01-17T22:23:42.140 回答