您不能覆盖 ContentDialog 等中的过渡。它们旨在成为获得标准行为的简单方法,并且将始终使用 PopupThemeTransition。
如果您想要非标准行为,那么您可以编写一个使用您自己的 TransitionCollection 的自定义控件。我找不到任何现有的样本,但请查看 Callisto 的 CustomDialog 了解一般概念。它模仿了 Windows MessageDialog,内容位于全屏调光窗口上方的水平居中条中,但切换 UI 以匹配 Windows Phone 的顶部停靠面板应该不难。
一旦您掌握了自己的控制权,就可以使用您喜欢的任何过渡。我没有方便的 WP8 设备来查看过渡是什么,但带有 Edge="Left" 的 PaneThemeTransition 听起来与您的描述相符。如果没有,那么一旦您进行了转场,您可以将其换成您喜欢的转场,或者删除所有转场并应用您自己的情节提要动画。我要么坚持使用对用户有意义的标准过渡,要么进行完全自定义,因为主题过渡可能会再次改变。
创建一个看起来正确的面板非常容易。棘手的部分是如何显示控件。如果您将它包含在您的 Xaml 中,因此它是可视化树的一部分,那么您就可以显示它。如果它不在可视树中,那么您需要将其添加到可视树中或将其托管在弹出窗口中。
这是一个快速而肮脏的 UserControl,它在 Popup 中托管自己并使用 PaneThemeTransition 从右侧滑入。
<UserControl
x:Class="App199.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App199"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
PointerReleased="UserControl_PointerReleased">
<UserControl.Transitions>
<TransitionCollection>
<PaneThemeTransition Edge="Left"/>
</TransitionCollection>
</UserControl.Transitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition x:Name="statusBarRow" Height="0" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row ="1" Background="Black">
<Ellipse Height="100" Width="100" Fill="Yellow" />
<TextBlock>Lorem Ipsum</TextBlock>
<Rectangle Height="100" Width="100" Fill="Red" />
</StackPanel>
<Border Grid.Row="2" Background="#7F000000" />
</Grid>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Phone.UI.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace App199
{
public sealed partial class MyUserControl1 : UserControl
{
Popup hostPopup;
public MyUserControl1()
{
this.InitializeComponent();
hostPopup = new Popup();
hostPopup.Child = this;
Loaded += MyUserControl1_Loaded;
Unloaded += MyUserControl1_Unloaded;
}
void MyUserControl1_Loaded(object sender, RoutedEventArgs e)
{
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void MyUserControl1_Unloaded(object sender, RoutedEventArgs e)
{
HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
}
public void Show()
{
this.Height = Window.Current.Bounds.Height;
this.Width = Window.Current.Bounds.Width;
var occRect = Windows.UI.ViewManagement.StatusBar.GetForCurrentView().OccludedRect;
statusBarRow.Height = new GridLength(occRect.Height);
hostPopup.IsOpen = true;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
if (hostPopup.IsOpen)
{
hostPopup.IsOpen = false;
e.Handled = true;
}
}
private void UserControl_PointerReleased(object sender, PointerRoutedEventArgs e)
{
hostPopup.IsOpen = false;
}
}
}