当我单击应该启动动画的按钮时,为什么动画没有运行?

时间:2018-10-02 12:45:03

标签: c# .net wpf animation mvvm

我正在尝试获取黑匣子

<StackPanel>
                <ToggleButton Height="30"
                              Content="Add Products"
                              FontSize="18"
                              Foreground="White"
                              Style="{DynamicResource MenuToggleButtonStyle}"
                              x:Name="theMenuButton"/>
            </StackPanel>

当我单击ToggleButton时在x轴上移动,但是由于某种原因它不会移动,我没有收到任何错误或任何提示,几乎就像它没有绑定一样。

为什么Box(堆栈面板)不动?

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <Grid.Resources>
            <system:Double x:Key="SlideOffSet">130</system:Double>

            <Storyboard x:Key="slideRight">
                <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)"
                                 From="0" To="{StaticResource SlideOffSet}"
                                 Duration="0:0:0.3"/>
            </Storyboard>
        </Grid.Resources>

        <Grid Column="0"
              Background="#272727">
            <StackPanel>
                <ToggleButton Height="30"
                              Content="Add Products"
                              FontSize="18"
                              Foreground="White"
                              Style="{DynamicResource MenuToggleButtonStyle}"
                              x:Name="theMenuButton"/>
            </StackPanel>
        </Grid>

        <Grid Column="1">
            <StackPanel Width="100"
                        Height="100"
                        Background="#212121"
                        x:Name="Box">

                <StackPanel.Style>
                    <Style TargetType="StackPanel">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsChecked, ElementName=theMenuButton}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource slideRight}" />
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Style>
            </StackPanel>

        </Grid>
    </Grid>



    <Window.Resources>
        <Style TargetType="ToggleButton"
               x:Key="MenuToggleButtonStyle">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontSize" Value="18"/>
            <Setter Property="FontSize" Value="18"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Background="{TemplateBinding Background}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="Orange"></Setter>
                </Trigger>

                <Trigger Property="IsPressed" Value="True">     
                    <Setter Property="Background" Value="White"/>
                </Trigger>

                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="Green"/>
                </Trigger>
            </Style.Triggers>
        </Style>


    </Window.Resources>

0 个答案:

没有答案