微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PopUp.xaml_1130

前台

<UserControl x:Class="SilverlightProjectTry.PopUp"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="800">

    <UserControl.Resources>
        <Storyboard x:Name="Storyboard1">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="userControl" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-14.881999969482422"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="#FFBDC8C9">
        <StackPanel>
            <TextBlock Height="26"  VerticalAlignment="Bottom" Text="" textwrapping="Wrap" x:Name="MessageText" HorizontalAlignment="Left" Width="158"/>
            <TextBlock Height="26" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="164" Text="Silverlight弹出窗口示例" textwrapping="Wrap"/>
            <Button Height="40" HorizontalAlignment="Left"  x:Name="OpenBox" VerticalAlignment="Top" Width="100" Content="弹出窗口" Click="OpenBox_Click"/>
            <Button HorizontalAlignment="Left" x:Name="OpenModalBox" Width="100" Content="弹出模式窗口" Height="40" Click="OpenModalBox_Click"/>
            <Button Height="40" x:Name="OpenMessage" VerticalAlignment="Top" Content="弹出消息" Width="100" HorizontalAlignment="Right" Click="OpenMessage_Click"/>
            <Button  x:Name="OpenModalMessage" Content="弹出模式消息" HorizontalAlignment="Right" Width="100" Height="40" d:LayoutOverrides="Height" VerticalAlignment="Top" Click="OpenModalMessage_Click"/>
            <Rectangle  Fill="#FFFFFFFF" stroke="#FF000000" strokeThickness="2"/>
            <TextBlock Height="Auto" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="Auto" RenderTransformOrigin="0.32,1.087" Text="消息框设置" textwrapping="Wrap" d:LayoutOverrides="Height"/>
            <TextBlock Height="17" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="Auto" Text="标题:" textwrapping="Wrap"/>
            <TextBlock Height="17"  VerticalAlignment="Top" Width="Auto" textwrapping="Wrap" d:LayoutOverrides="Width"><Run Text="内容"/><Run Text=":"/></TextBlock>
            <TextBox Height="Auto" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="108" Text="填写标题" textwrapping="Wrap" x:Name="Title" d:LayoutOverrides="Height"/>
            <TextBox Height="Auto"  VerticalAlignment="Top" Text="填写内容" textwrapping="Wrap" HorizontalAlignment="Left" Width="108" x:Name="Message" d:LayoutOverrides="Height"/>
            <TextBlock Height="18" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="Auto" Text="按钮:" textwrapping="Wrap"/>
            <ComboBox Height="Auto" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="108" x:Name="ButtonType" d:LayoutOverrides="Height">
                <ComboBoxItem Tag="YesNo" Content="Yes/No" IsSelected="True"/>
                <ComboBoxItem Tag="YesNoCancle" Content="Yes/No/Cancle"/>
                <ComboBoxItem Tag="OkCancle" Content="Ok/Cancle"/>
                <ComboBoxItem Tag="RetryAbort" ToolTipService.ToolTip="" Content="Retry/Abort"/>
                <ComboBoxItem Tag="RetryAbortCancle" ToolTipService.ToolTip="" Content="Retry/Abort/Cancle"/>
            </ComboBox>
            <TextBlock Height="18" VerticalAlignment="Top" Width="Auto" textwrapping="Wrap" d:LayoutOverrides="Width"><Run Text="特效"/><Run Text=":"/></TextBlock>
            <ComboBox Height="Auto"  VerticalAlignment="Top" HorizontalAlignment="Left" Width="108" x:Name="Effects" d:LayoutOverrides="Height">
                <ComboBoxItem Tag="NoEffect" Content="无特效" IsSelected="True"/>
                <ComboBoxItem Tag="Fade" Content="渐隐"/>
                <ComboBoxItem Tag="Zoom" Content="缩放"/>
            </ComboBox>
            <TextBlock  Width="Auto" textwrapping="Wrap" Height="18" VerticalAlignment="Top" Text="图标:" d:LayoutOverrides="Width"/>
            <ComboBox Height="Auto"  x:Name="Icon" VerticalAlignment="Top" HorizontalAlignment="Left" Width="108">
                <ComboBoxItem Tag="No" Content="无图标" IsSelected="True"/>
                <ComboBoxItem Tag="Caution" Content="警告"/>
                <ComboBoxItem Tag="Error" Content="错误"/>
                <ComboBoxItem Tag="Caution" Content="提示"/>
                <ComboBoxItem Tag="@R_10_4045@ion" Content="信息"/>
                <ComboBoxItem Tag="Question" Content="询问"/>
            </ComboBox>
        </StackPanel>
    </Grid>
</UserControl>

后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GDev.PopupBox;
using SilverlightApplication1;

namespace SilverlightProjectTry
{
    public partial class PopUp : UserControl
    {
        public PopUp()
        {
            InitializeComponent();
        }
        private Effect GetEffect(FrameworkElement target)
        {
            switch ((string)((ComboBoxItem)Effects.SelectedItem).Tag)
            {
                case "NoEffect":
                    return GDev.PopupBox.Effect.NoEffect(target);
                case "Fade":
                    return GDev.PopupBox.Effect.Fade(target);
                case "Zoom":
                    return GDev.PopupBox.Effect.Zoom(target);
                default:
                    return GDev.PopupBox.Effect.NoEffect(target);
            }

        }

        private void OpenBox_Click(object sender,RoutedEventArgs e)
        {
            PopupService service = PopupService.GetServiceFor(LayoutRoot);
            BoxPage Box = service.GetBoxPage(
                new MyControl(),//显示的控件
                Title.Text,//标题
                true,//是否可以拖动
                true //是否显示关闭图标
            );
            Box.Effect = GetEffect(Box);
            Box.ShowComplete += new EventHandler(Box_ShowComplete);
            Box.CloseComplete += new EventHandler(Box_CloseComplete);
            Box.Show();
        }

        private void Box_CloseComplete(object sender,EventArgs e)
        {
            MessageText.Text = "关闭了窗口";
        }

        private void Box_ShowComplete(object sender,EventArgs e)
        {
            MessageText.Text = "打开了新窗口";
        }

        private void Box_ButtonClick(object sender,EventArgs e)
        {
            MessageText.Text = "你点击了:" + ((MessagePage)sender).Result;
        }

        private void OpenModalBox_Click(object sender,
                Title.Text,
                true,
                true
            );
            Box.Effect = GetEffect(Box);
            Box.ShowComplete += new EventHandler(Box_ShowComplete);
            Box.CloseComplete += new EventHandler(Box_CloseComplete);
            Box.ShowAsModal();
        }

        private void OpenMessage_Click(object sender,RoutedEventArgs e)
        {
            PopupService service = PopupService.GetServiceFor(LayoutRoot);
            MessagePage Box = service.GetMessagePage(
                Message.Text,
                GetButtonType(),
                GetIcon()
            );
            Box.Effect = GetEffect(Box);
            Box.ShowComplete += new EventHandler(Box_ShowComplete);
            Box.ButtonClick += new EventHandler(Box_ButtonClick);
            Box.Show();
        }

        private void OpenModalMessage_Click(object sender,
                GetIcon()
            );
            Box.Effect = GetEffect(Box);
            Box.ShowComplete += new EventHandler(Box_ShowComplete);
            Box.ButtonClick += new EventHandler(Box_ButtonClick);
            Box.ShowAsModal();
        }

        private MessageBoxIcon GetIcon()
        {
            switch ((string)((ComboBoxItem)Icon.SelectedItem).Tag)
            {
                case "No":
                    return null;
                case "Warn":
                    return MessageBoxIcon.Warn;
                case "Caution":
                    return MessageBoxIcon.Caution;
                case "Error":
                    return MessageBoxIcon.Error;
                case "@R_10_4045@ion":
                    return MessageBoxIcon.@R_10_4045@ion;
                case "Question":
                    return MessageBoxIcon.Question;
                default:
                    return null;
            }
        }

        private MessageBoxButtonType GetButtonType()         {             string type = (string)((ComboBoxItem)ButtonType.SelectedItem).Tag;             return (MessageBoxButtonType)Enum.Parse(                 typeof(MessageBoxButtonType),                type,                true             );         }     } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐