Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 点击按钮触发故事板_C#_Wpf_Xaml_Triggers_Styles - Fatal编程技术网

C# 点击按钮触发故事板

C# 点击按钮触发故事板,c#,wpf,xaml,triggers,styles,C#,Wpf,Xaml,Triggers,Styles,我有一个包含一些按钮的Stackpanel (这些按钮的作用是,单击后,每个按钮都会将页面加载到一个框架中) 这些按钮的样式称为“MyButton” 这种样式的作用是,当鼠标进入时,它将按钮宽度更改为200,当鼠标离开时,它将按钮宽度更改为64。 基本上,我想做的是,当按下按钮时,我希望宽度保持在200,但这并不是那么简单,因为我还希望当按下另一个相同样式的按钮时,我希望第一个按钮回到正常宽度(64),然后我希望最近按下的按钮的宽度等于200 我想我需要解释更多。 例如: (只是澄清一下

我有一个包含一些按钮的Stackpanel

(这些按钮的作用是,单击后,每个按钮都会将页面加载到一个框架中)


这些按钮的样式称为“MyButton”


这种样式的作用是,当鼠标进入时,它将按钮宽度更改为200,当鼠标离开时,它将按钮宽度更改为64。 基本上,我想做的是,当按下按钮时,我希望宽度保持在200,但这并不是那么简单,因为我还希望当按下另一个相同样式的按钮时,我希望第一个按钮回到正常宽度(64),然后我希望最近按下的按钮的宽度等于200

我想我需要解释更多。 例如:

(只是澄清一下:鼠标进入/离开触发器工作正常,因此没有任何问题)

让我们以AjButton和ConsulterButton为例,当我点击AjButton时,我希望它的宽度保持在200(因为鼠标悬停是真的,所以它已经是200),现在当我点击ConsulterButton时,我希望它的宽度保持在200,AjButton的宽度回到64

你可能会说,我可以使用IsFocused属性,但它不会很好地工作,因为在我的项目中,我有一个框架,当我聚焦在它上时,按钮宽度会回到64

我花了很多时间寻找这个问题的解决方案,但什么也没找到。。 问题是我是新手,所以我真的不知道在谷歌上写什么,你们甚至可以从这篇文章的标题上看出来

<StackPanel x:Name="Buttons" HorizontalAlignment="Left" VerticalAlignment="Top" Height="64" Width="1100" Orientation="Horizontal" Margin="0,31,0,0">
        <Button x:Name="AjoutButton" Width="64" Content="" Style="{DynamicResource MyButton}" Click="AjoutPressed">
            <Button.Background>
                <ImageBrush ImageSource="Backgrounds/Buttons/AjoutButton.png" Stretch="UniformToFill" AlignmentX="Left"/>
            </Button.Background>
        </Button>
        <Button x:Name="ConsulterButton" Width="64" Content="" Style="{DynamicResource MyButton}" Click="ConsulterPressed">
            <Button.Background>
                <ImageBrush ImageSource="Backgrounds/Buttons/ConsultationButton.png" Stretch="UniformToFill"  AlignmentX="Left"/>
            </Button.Background>
        </Button>
    </StackPanel>
<Style x:Key="MyButton" TargetType="{x:Type Button}">
        <Setter Property="FocusVisualStyle">
            <Setter.Value>
                <Style>
                    <Setter Property="Control.Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle Margin="2" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush" Value="#FF707070"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard >
                                        <DoubleAnimation Storyboard.TargetProperty="Width" From="64" Duration="0:0:.2" To="200"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard >
                                        <DoubleAnimation Storyboard.TargetProperty="Width" From="200" Duration="0:0:.2" To="64"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>                                                   
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>