MessagePageWdd.xaml_1130

前台

<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"  x:Class="GDev.PopupBox.MessagePageWdd"
    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"
             xmlns:Theme="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.Toolkit"
    mc:Ignorable="d"
   d:DesignWidth="640" d:DesignHeight="480" Loaded="UserControl_Loaded" Width="385" MouseLeftButtonDown="UserControl_MouseLeftButtonDown">


    <Border x:Name="LayoutRoot" Width="Auto" Height="Auto" Background="#FFFFFFFF" BorderBrush="#FF92E785" BorderThickness="1,1,1,1"  >
        <!--CornerRadius="10,10,10,10"-->
        <StackPanel Height="Auto" Width="Auto" x:Name="LayoutPanel">
            <Border Height="24" VerticalAlignment="Top" Width="Auto" BorderBrush="#FF000000" BorderThickness="0,0,0,1">
                <StackPanel Height="Auto" Width="Auto" x:Name="TitlePanel" Background="#00000000" Orientation="Horizontal">

                    <TextBlock Height="Auto" x:Name="TitleText" Width="Auto" Text="" TextWrapping="Wrap" Margin="5,0,0,0" VerticalAlignment="Center"/>

                </StackPanel>
            </Border>
            <StackPanel Height="Auto" Width="Auto" x:Name="ContentPanel" Orientation="Horizontal" Background="{x:Null}">
                <StackPanel Height="Auto" Width="Auto" Orientation="Vertical">
                    <TextBlock Height="Auto" Width="Auto" Text="" TextWrapping="Wrap" Margin="10,10,10,10" x:Name="MessageText"
                               Visibility="Collapsed"/>
                    <StackPanel Height="Auto" Width="Auto" Margin="10,10,10,10"  x:Name="MessageOne"></StackPanel>
                </StackPanel>
            </StackPanel>
            <Border Height="Auto" VerticalAlignment="Stretch" Width="Auto" BorderBrush="#FF000000" BorderThickness="0,1,0,0">

                <StackPanel Height="Auto" Width="Auto" x:Name="ButtonPanel" Orientation="Horizontal" Background="{x:Null}" HorizontalAlignment="Stretch"/>

            </Border>
        </StackPanel>
    </Border>

</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 System.Text.RegularExpressions;

namespace GDev.PopupBox
{
    /// <summary>
    /// 添加人:吴兆娟
    /// </summary>
    public partial class MessagePageWdd : UserControl, IPopupBox
    {
        #region 属性

        public string Title
        {
            get
            {
                return TitleText.Text;
            }
            set
            {
                TitleText.Text = value;
            }
        }

        public string Message
        {
            get
            {
                return MessageText.Text;
            }
            set
            {
                MessageText.Text = value;
            }
        }

        public UIElement MessageContent
        {
            get
            {
                return MessageOne.Children[0];
            }
            set
            {
                MessageOne.Children.Add(value);
            }
        }

        public MessageBoxIcon Icon
        {
            get;
            set;
        }

        public MessageBoxButtonType ButtonType
        {
            get;
            set;
        }

        public MessageBoxButtonResult Result
        {
            get;
            private set;
        }

        public Border Border
        {
            get
            {
                return LayoutRoot;
            }
        }

        public Panel TitleElement
        {
            get
            {
                return TitlePanel;
            }
        }

        public Panel ContentElement
        {
            get
            {
                return ContentPanel;
            }
        }

        public Panel ButtonElement
        {
            get
            {
                return ButtonPanel;
            }
        }

        #endregion

        #region 事件

        public event EventHandler ButtonClick;

        protected virtual void OnButtonClick(EventArgs e)
        {
            EventHandler handler = ButtonClick;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public event EventHandler ShowComplete;

        protected virtual void OnShowComplete(EventArgs e)
        {
            EventHandler handler = ShowComplete;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion

        public MessagePageWdd()
        {
            // 需要初始化变量
            InitializeComponent();
        }

        #region 辅助方法

        private void BuildButton()
        {
            string typeEnum = ButtonType.ToString();
            typeEnum = Regex.Replace(
                typeEnum,
                "[A-Z]",
                match => ":" + match.Value
            );
            string[] types = typeEnum.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string type in types)
            {
                AddButton(type);
            }
        }

        private void AddButton(string text)
        {
            Button button = new Button();
            button.Content = text;
            button.Width = 60;
            button.HorizontalAlignment = HorizontalAlignment.Center;
            button.Margin = new Thickness(5, 3, 5, 3);
            button.Click += new RoutedEventHandler(Button_Click);
            ButtonPanel.Children.Add(button);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            if (button != null)
            {
                Result = (MessageBoxButtonResult)Enum.Parse(
                    typeof(MessageBoxButtonResult),
                    (string)button.Content,
                    true
                );
                Close();
            }
        }

        private void BuildContent(FrameworkElement icon)
        {
            if (icon != null)
            {
                icon.Width = 64;
                icon.Height = 64;
                icon.HorizontalAlignment = HorizontalAlignment.Left;
                icon.VerticalAlignment = VerticalAlignment.Top;
                icon.Margin = new Thickness(5, 10, 5, 10);
                //ContentPanel.Children.Insert(0, icon);
            }
        }

        private void BuildTitle(FrameworkElement icon)
        {
            if (icon != null)
            {
                icon.Width = 18;
                icon.Height = 18;
                icon.HorizontalAlignment = HorizontalAlignment.Left;
                icon.VerticalAlignment = VerticalAlignment.Center;
                icon.Margin = new Thickness(2, 0, 0, 0);
                TitlePanel.Children.Insert(0, icon);
            }
            TitleText.Text = Title;
        }

        #endregion

        #region IPopupBox 成员

        public LayoutMask Mask
        {
            get;
            set;
        }

        public UIElement DragMouseCaptureArea
        {
            get
            {
                return TitlePanel;
            }
        }

        public FrameworkElement Element
        {
            get
            {
                return this;
            }
        }

        public Point LastDragPosition
        {
            get;
            set;
        }

        public bool IsDraggable
        {
            get;
            set;
        }

        public bool IsDragging
        {
            get;
            set;
        }

        public new Effect Effect
        {
            get;
            set;
        }

        public bool IsModal
        {
            get;
            private set;
        }

        public void Show()
        {
            //设定ZIndex
            Canvas.SetZIndex(this, Mask.MaxZIndex + 1);

            //先将控件隐藏以显示动画效果
            Visibility = Visibility.Collapsed;

            Mask.AddBox(this);
        }

        public void ShowAsModal()
        {
            IsModal = true;
            Show();
        }

        public void Close()
        {
            //进行退出动画
            Effect.Complete += new EventHandler(Effect_CompleteOnOut);
            Effect.PerformOutEffect();
        }

        #endregion

        #region 事件方法

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement titleIcon = null;
            FrameworkElement contentIcon = null;

            if (Icon != null)
            {
                titleIcon = Icon.GetTitleIcon();
                contentIcon = Icon.GetContentIcon();
            }
            BuildTitle(titleIcon);
            BuildContent(contentIcon);
            BuildButton();

            Effect.Complete += new EventHandler(Effect_CompleteOnShow);
            Visibility = Visibility.Visible;
            UpdateLayout();
            //居中
            Mask.CenterToMask(this);
            Effect.PerformInEffect();
        }

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Canvas.SetZIndex(this, Mask.MaxZIndex + 1);
        }

        private void Effect_CompleteOnShow(object sender, EventArgs e)
        {
            Effect.Complete -= Effect_CompleteOnShow;

            OnShowComplete(EventArgs.Empty);
        }

        private void Effect_CompleteOnOut(object sender, EventArgs e)
        {
            //有可能由于多次关闭导致此事件执行多次
            //这种情况下第一次执行是有效的
            //以后的事件会因为Mask.RemoveBox方法的调用使Mask为null
            //因此需要进行判断
            if (Mask != null)
            {
                //从Mask中移除
                Mask.RemoveBox(this);

                Effect.Complete -= Effect_CompleteOnOut;

                OnButtonClick(EventArgs.Empty);
            }
        }

        #endregion
    }
}

 

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值