我有一个按钮,里面有另一个按钮。如何单击此内部按钮?

时间:2016-09-28 07:45:40

标签: c# wpf

       <Style x:Key="CSButton" TargetType="Button">
        <Setter Property="FontFamily" Value="Segoe UI"/>
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="CSImageAnimation">
                            <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="image">
                                <EasingPointKeyFrame KeyTime="0" Value="0.5,0.5"/>
                                <EasingPointKeyFrame KeyTime="0:0:0.3" Value="0.5,0.5"/>
                                <EasingPointKeyFrame KeyTime="0:0:0.6" Value="0.5,0.5"/>
                            </PointAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="image">
                                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="-1"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Border
                            CornerRadius="2" Opacity="1">
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFFFE27F" Offset="0"/>
                                <GradientStop Color="#FFFFC500" Offset="1"/>
                            </LinearGradientBrush>
                        </Border.Background>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <StackPanel Grid.Column="0" Grid.Row="0">
                                <TextBlock x:Name="CSLabel" HorizontalAlignment="Center" Margin="0,20,0,20"
                                           VerticalAlignment="Top"
                                           Text="Current Session" FontSize="20"
                                           Foreground="#FF303030"/>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">

                                    <Button x:Name="bttnPreviousSession" Height="30" Width="30" 
                                            Style="{StaticResource LeftInsideButton}" Command="{Binding UpdateSessionCommand}" />
                                    <Image x:Name="image" Margin="0,0,0,0"
                                    Source="/Overseer;component/Resources/CurrentSession.png" 
                                       Height="120">
                                        <Image.RenderTransform>
                                            <TransformGroup>
                                                <ScaleTransform/>
                                                <SkewTransform/>
                                                <RotateTransform/>
                                                <TranslateTransform/>
                                            </TransformGroup>
                                        </Image.RenderTransform>
                                    </Image>
                                    <Button x:Name="bttnNextSession" Height="30" Width="30" Style="{StaticResource RightInsideButton}"/>

                                </StackPanel>

                                <TextBlock x:Name="CSYLabel" HorizontalAlignment="Center" Margin="0,5,0,0"
                                           VerticalAlignment="Top"
                                           Text="{Binding SessionUsed}" FontSize="18"
                                           Foreground="#FF303030"/>
                            </StackPanel>

                            <StackPanel Grid.Column="0" Grid.Row="1" Margin="10,0,10,10"
                                        HorizontalAlignment="Stretch" VerticalAlignment="Center">

                                <Rectangle  Fill="#FFFFF300"
                                       Height="1" Width="220" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,10,0,0"/>

                                <TextBlock x:Name="ContentLabel" HorizontalAlignment="Center"
                                           Text="1980" FontFamily="Segoe UI" VerticalAlignment="Center"
                                           FontSize="25" Foreground="White"/>
                                <TextBlock x:Name="RLabel" HorizontalAlignment="Center"
                                           Text="Strength" FontSize="24" VerticalAlignment="Center"
                                           Foreground="#FF303030"/>

                            </StackPanel>

                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <EventTrigger RoutedEvent="UIElement.MouseEnter">
                            <BeginStoryboard Storyboard="{StaticResource CSImageAnimation}"/>
                        </EventTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

我想点击CSButton Style中的bttnPreviousSession按钮。我已经通过了命令,但它无法正常工作。单击它将触发主按钮上的命令。我知道如何使用代码来实现这一点,但是希望通过视图或视图模型来实现MVVM模式。

0 个答案:

没有答案