添加StoryBoard到Galasoft的EventToCommand

时间:2015-08-26 13:46:25

标签: c# wpf mvvm-light

我正在尝试将故事板添加到事件触发器中,事件触发器正在使用Galasoft,我认为这可能无法按预期工作。

我有一个DataGrid,当我双击一行时,我想在网格列的宽度上触发动画。

下面是我的XAML DataGrid:

<DataGrid SelectedItem="{Binding SelectedItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" RowHeaderWidth="0" RowHeight="22" ItemsSource="{Binding SquirrelData}" IsReadOnly="True" Grid.ColumnSpan="4" Name="dtSearch" Margin="10,5,10,10" ColumnWidth="*" Grid.Row="4" >
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseDoubleClick">
                <i:InvokeCommandAction Command="{Binding OpenDetail}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </DataGrid>

我无法在偶数触发后添加<BeginStoryboard>,因为事件触发器不是默认的事件触发器。

关于如何实现这一目标的任何建议?

1 个答案:

答案 0 :(得分:1)

以下是解决问题的两种方法:

  • ControlStoryboardAction
  • 中使用i:Interaction.Triggers
  • 不要使用i:Interaction.Triggers,而是使用常规触发器(已注释掉的那个)

代码:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="WpfApplication1.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Storyboard x:Key="Storyboard1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="button">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="88.314"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <!--<EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
        </EventTrigger>-->
    </Window.Triggers>
    <Grid Background="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseLeftButtonDown">
                <ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="104.234,113.568,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.5,0.5">
            <Button.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Button.RenderTransform>
        </Button>
    </Grid>
</Window>

专家提示:使用Blend for Visual Studio轻松地使用鼠标创建此类代码。