加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

xaml – 如何更改ContentDialog转换?

发布时间:2020-12-14 02:25:53 所属栏目:Windows 来源:网络整理
导读:Windows Phone 8.1为对话框和弹出窗口引入了一个新的转换,看起来像 Venetian blind.我不喜欢这个;我更喜欢它在Windows Phone 8中的样子,它可以旋转/倾斜.有没有办法改变这个? 我尝试过这样的事情: ContentDialog.Transitions TransitionCollection /Transi
Windows Phone 8.1为对话框和弹出窗口引入了一个新的转换,看起来像 Venetian blind.我不喜欢这个;我更喜欢它在Windows Phone 8中的样子,它可以旋转/倾斜.有没有办法改变这个?

我尝试过这样的事情:

<ContentDialog.Transitions>
    <TransitionCollection>
    </TransitionCollection>
</ContentDialog.Transitions>

但它并没有改变过渡.

解决方法

您无法覆盖ContentDialog等中的过渡.它们旨在获得标准行为的简单方法,并始终使用PopupThemeTransition.

如果您想要非标准行为,那么您可以编写一个使用您自己的TransitionCollection的自定义控件.我找不到任何现有的样本,但请查看Callisto的CustomDialog的一般概念.它模仿Windows MessageDialog,其内容位于全屏调光窗口的水平居中栏中,但是移动UI以匹配Windows Phone的顶部停靠面板应该不难.

一旦掌握了自己的控制权,就可以使用自己喜欢的任何一种转换.我没有WP8设备方便看到转换是什么,但是带有Edge =“Left”的PaneThemeTransition听起来像是符合你的描述.如果没有,那么一旦你有转换,你可以将它交换为你喜欢的转换或删除所有转换并应用你自己的故事板动画.我要么坚持使用对用户有意义的标准转换,要么完全自定义,因为主题转换可能会再次发生变化.

创建一个看起来正确的面板非常简单.棘手的部分是如何显示控件.如果你将它包含在你的Xaml中,那么它就是可视树的一部分,那么你就可以展示它.如果它不在可视化树中,那么您需要将其添加到可视树中或将其托管在Popup中.

这是一个快速而脏的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;
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读