有幾種方法可以解決這個問題。你可以用interactivity
和behaviors
替換你的事件,但由於你沒有在你的示例代碼中使用它們,所以我不會分享它。所以我寫了一個代碼示例來讓你的動畫工作。
我已經創建了具有native
和storyboard
動畫一些示例代碼:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.Resources>
<Storyboard x:Name="ShowPopup">
<PopInThemeAnimation Storyboard.TargetName="MyPopup" />
</Storyboard>
<Storyboard x:Name="HidePopup">
<PopOutThemeAnimation Storyboard.TargetName="MyPopup" />
</Storyboard>
</Grid.Resources>
<Popup x:Name="MyPopup" IsOpen="True"
HorizontalAlignment="Center" VerticalAlignment="Center">
<Popup.Transitions>
<TransitionCollection>
<PopupThemeTransition />
</TransitionCollection>
</Popup.Transitions>
<Grid Height="200" Width="200" Background="Red">
<StackPanel>
<Button Content="Hide (Native)" HorizontalAlignment="Center" Click="hide_native_click"/>
<Button Content="Hide (Storyboard)" HorizontalAlignment="Center" Click="hide_storyboard_click"/>
</StackPanel>
</Grid>
</Popup>
<StackPanel>
<Button Content="Show Popup (Native)" HorizontalAlignment="Left" VerticalAlignment="Top" Click="show_native_click"/>
<Button Content="Show Popup (Storyboard)" HorizontalAlignment="Left" VerticalAlignment="Top" Click="show_storyboard_click"/>
</StackPanel>
</Grid>
和後面的代碼看起來像下面:
private void hide_native_click(object sender, RoutedEventArgs e)
{
MyPopup.IsOpen = false;
}
private void hide_storyboard_click(object sender, RoutedEventArgs e)
{
HidePopup.Begin();
}
private void show_native_click(object sender, RoutedEventArgs e)
{
MyPopup.IsOpen = true;
}
private void show_storyboard_click(object sender, RoutedEventArgs e)
{
ShowPopup.Begin();
}
你確定使用彈出?如果你想顯示一個彈出來的按鈕,那麼你正在尋找一個飛出。 –