我有一個StackPanel和一個按鈕。初始化按鈕的內容應該是< <當按鈕被點擊時,StackPanel的內容應該會崩潰,並且按鈕文本應該變成>>其中崩潰正在發生。再次按下相同的按鈕時,我希望顯示的內容和文本應該是< <,我不確定如何操作。wpf動畫隱藏和摺疊按鈕上的面板點擊
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" x:Name="stkEasyLocatePanel" Loaded="stkEasyLocatePanel_Loaded" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,0,0,28"></StackPanel>
<Button Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,5,0,0" Panel.ZIndex="140" Height="20" Width="25" Background="Transparent" Content="<<">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard x:Name="HideStackPanel">
<DoubleAnimation Storyboard.TargetName="stkEasyLocatePanel" Storyboard.TargetProperty="Width" From="330" To="0" Duration="0:0:0.3">
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseIn"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
<BeginStoryboard>
<!--This part dosent work. The content collapses and shows on a single click. But I want it to happen on two clicks of same button-->
<Storyboard x:Name="ShowStackPanel">
<DoubleAnimation Storyboard.TargetName="stkEasyLocatePanel" Storyboard.TargetProperty="Width" From="0" To="330" Duration="0:0:0.3">
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseIn"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
你想在純xaml中使用觸發器還是使用VisualStateManager? –
他們兩個都很好。但我想知道爲正常按鈕做這個的解決方案。 – nikhil
爲什麼正常按鈕很重要?如果需要,可以設計一個切換來模擬正常按鈕的設計/行爲,@AnjumSKhan答案是一個正確的選項。要使用普通按鈕,您需要在後面的代碼中處理條件表達式,在我看來,純xaml方法在這種情況下很好。 –