Несколько DataTriggers - переопределение раскадровки - PullRequest
4 голосов
/ 15 декабря 2011

У меня есть два DataTriggers, привязанных к свойству (Side), но можно запустить только одну раскадровку (ту, что в последних DataTriggers).

Почему?

Я чувствую, что последняя раскадровка перекрывает первую

<Border x:Name="layout" Background="Transparent" BorderBrush="#BAC8CE" BorderThickness="1" CornerRadius="5">
  <Border.Style>
    <Style TargetType="{x:Type Border}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding Side}" Value="Up">
          <DataTrigger.EnterActions>
            <BeginStoryboard>
              <Storyboard>
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
                                Duration="00:00:01"
                                From="Transparent"
                                To="Green"/>
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
                                Duration="00:00:00.5" 
                                From="Green"
                                To="Transparent"/>
              </Storyboard>
            </BeginStoryboard>
          </DataTrigger.EnterActions>
        </DataTrigger>
        <DataTrigger Binding="{Binding Side}" Value="Down">
          <DataTrigger.EnterActions>
            <BeginStoryboard>
              <Storyboard>
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
                                Duration="00:00:01" 
                                From="Transparent"
                                To="Red"/>
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
                                Duration="00:00:00.5" 
                                From="Red"
                                To="Transparent"/>
              </Storyboard>
            </BeginStoryboard>
          </DataTrigger.EnterActions>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Border.Style>
</Border>

Ответы [ 2 ]

8 голосов
/ 15 декабря 2011

Я бы предложил остановить вашу раскадровку до запуска другой:

<Border x:Name="layout" Background="Transparent" BorderBrush="#BAC8CE" BorderThickness="1" CornerRadius="5">
    <Border.Style>
        <Style TargetType="{x:Type Border}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Side}" Value="Up">
                    <DataTrigger.EnterActions>
                        <StopStoryboard BeginStoryboardName="BeginStoryboardTwo" />
                        <BeginStoryboard x:Name="BeginStoryboardOne">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
                                                Duration="00:00:01"
                                                From="Transparent"
                                                To="Green"/>
                                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
                                                Duration="00:00:00.5" 
                                                From="Green"
                                                To="Transparent"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding Side}" Value="Down">
                    <DataTrigger.EnterActions>
                        <StopStoryboard BeginStoryboardName="BeginStoryboardOne" />
                        <BeginStoryboard x:Name="BeginStoryboardTwo" >
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
                                                Duration="00:00:01" 
                                                From="Transparent"
                                                To="Red"/>
                                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
                                                Duration="00:00:00.5" 
                                                From="Red"
                                                To="Transparent"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
    <TextBlock Text="Hello World!" />
</Border>
1 голос
/ 15 декабря 2011

попробуйте следующее решение, поместите ваше второе действие ввода данных датгергера на первое действие выхода выхода данных

<Border x:Name="layout"
        Grid.Row="1"
        Background="Transparent"
        BorderBrush="#BAC8CE"
        BorderThickness="1"
        CornerRadius="5">
  <Border.Style>
    <Style TargetType="{x:Type Border}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding Side, ElementName=uc, Mode=OneWay}"
                      Value="Up">
          <DataTrigger.EnterActions>
            <BeginStoryboard>
              <Storyboard>
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
                                Duration="00:00:05"
                                From="Transparent"
                                To="Green" />
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
                                Duration="00:00:00.5"
                                From="Green"
                                To="Transparent" />
              </Storyboard>
            </BeginStoryboard>
          </DataTrigger.EnterActions>
          <DataTrigger.ExitActions>
            <BeginStoryboard>
              <Storyboard>
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
                                Duration="00:00:05"
                                From="Transparent"
                                To="Red" />
                <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
                                Duration="00:00:00.5"
                                From="Red"
                                To="Transparent" />
              </Storyboard>
            </BeginStoryboard>
          </DataTrigger.ExitActions>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Border.Style>
</Border>

надеюсь, это поможет

...