MessageBoxControl

    <Grid x:Name="LayoutRoot" Background="Pink" VerticalAlignment="Top" >
        <Grid.Resources>
            <Storyboard x:Name="storyboard">
                <DoubleAnimation Storyboard.TargetName="image"  Duration="0:0:0.8" To="360" Storyboard.TargetProperty="(UIElement.RenderTransform).RotateTransform.Angle" RepeatBehavior="Forever"></DoubleAnimation>             
            </Storyboard>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition ></RowDefinition>
        </Grid.RowDefinitions>
        <toolkit:DockPanel Name="dockPanel1">
            <Button x:Name="btn_close" toolkit:DockPanel.Dock="Right" Width="75" Content="关闭" HorizontalAlignment="Center" Click="btn_close_Click"></Button>
            <ScrollViewer x:Name="scr_message" toolkit:DockPanel.Dock="Right" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" BorderThickness="0,0,0,0">
                <TextBlock x:Name="txt_message" TextWrapping="Wrap" HorizontalAlignment="Right">
                </TextBlock>
            </ScrollViewer>
            <StackPanel toolkit:DockPanel.Dock="Left" VerticalAlignment="Center" HorizontalAlignment="Right">
                <Image x:Name="image" Height="15" RenderTransformOrigin="0.5,0.5">
                    <Image.RenderTransform>
                        <RotateTransform Angle="0"></RotateTransform>
                    </Image.RenderTransform>
                </Image>
            </StackPanel>
        </toolkit:DockPanel>
    </Grid>
</UserControl>

 

 

#region 属性变量
        private System.Windows.Threading.DispatcherTimer _timer = new System.Windows.Threading.DispatcherTimer();
        private int timetick_second;
        #endregion

        #region 控件事件
        public MessageBoxControl()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 初始化
        /// </summary>
        public void InitControl()
        {
            this._timer.Tick += new EventHandler(_timer_Tick);
            this.Visibility = Visibility.Collapsed;
            this.scr_message.MaxHeight = double.Parse(Lolana.Library.Configuration.ConfigurationManager.AppSettings["Scr_MaxHeight"].ToString());
            this.scr_message.MaxWidth = double.Parse(Lolana.Library.Configuration.ConfigurationManager.AppSettings["Scr_MaxWidth"].ToString());
            this.SetValue(Canvas.ZIndexProperty, int.Parse(Lolana.Library.Configuration.ConfigurationManager.AppSettings["Message_ZIndex"].ToString()));
        }
        /// <summary>
        /// 定时器事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _timer_Tick(object sender, EventArgs e)
        {
            this._timer.Stop();
            this.Hide();
        }
        /// <summary>
        /// 关闭
        /// </summary>
        public void MessageClose()
        {
            this.Hide();
        }
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="message"></param>
        /// <param name="imagetype"></param>
        public void MessageShow(string message, ImageType imagetype)
        {
            this.TimerStop();
            this.ClearMessage();
            this.AddMessage(message);
            this.ShowImage(imagetype);
            this.Pop();
        }
        /// <summary>
        /// 显示信息(自动关闭)
        /// </summary>
        /// <param name="message"></param>
        /// <param name="imagetype"></param>
        /// <param name="second"></param>
        public void MessageShow(string message, ImageType imagetype, int second)
        {
            this.TimerStop();
            this.ClearMessage();
            this.timetick_second = second;
            this.AddMessage(message);
            this.ShowImage(imagetype);
            this.Pop();
            this.TimerStart();
        }
        /// <summary>
        /// 追击信息
        /// </summary>
        /// <param name="message"></param>
        /// <param name="imagetype"></param>
        public void MessageAppend(string message, ImageType imagetype)
        {
            this.TimerStop();
            this.AddMessage(message);
            this.ShowImage(imagetype);
            this.Pop();
        }
        /// <summary>
        /// 追加信息(自动关闭)
        /// </summary>
        /// <param name="message"></param>
        /// <param name="imagetype"></param>
        /// <param name="secont"></param>
        public void MessageAppend(string message, ImageType imagetype, int second)
        {
            this.TimerStop();
            this.AddMessage(message);
            this.ShowImage(imagetype);
            this.timetick_second = second;
            this.Pop();
            this.TimerStart();
        }
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <returns></returns>
        public List<string> GetMessageList()
        {
            List<string> _l_str = new List<string>();
            foreach (Inline il in this.txt_message.Inlines)
            {
                if (il.GetType().Name == "Run")
                {
                    _l_str.Add(((Run)il).Text);
                }
            }
            return _l_str;
        }
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_close_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
        }
        #endregion

        #region 私有方法
        /// <summary>
        /// 显示
        /// </summary>
        private void Pop()
        {
            this.Visibility = Visibility.Visible;
        }
        /// <summary>
        /// 隐藏
        /// </summary>
        private void Hide()
        {
            this.TimerStop();
            this.ClearMessage();
            this.Visibility = Visibility.Collapsed;
        }
        /// <summary>
        /// 定时器开始
        /// </summary>
        private void TimerStart()
        {
            this._timer.Interval = new TimeSpan(this.timetick_second*10000000);//以100毫微秒为单位
            this._timer.Start();
        }
        /// <summary>
        /// 定时器停止
        /// </summary>
        private void TimerStop()
        {
            this._timer.Stop();
        }
        /// <summary>
        /// 追加信息
        /// </summary>
        /// <param name="message"></param>
        private void AddMessage(string message)
        {
            if (this.txt_message.Inlines.Count > 0)
            {
                this.txt_message.Inlines.Add(new LineBreak());
            }
            this.txt_message.Inlines.Add(new Run() { Text = message });
        }
        /// <summary>
        /// 清空信息
        /// </summary>
        private void ClearMessage()
        {
            this.txt_message.Inlines.Clear();
        }
        /// <summary>
        /// 设置图片
        /// </summary>
        /// <param name="imagetype"></param>
        private void ShowImage(ImageType imagetype)
        {
            this.storyboard.Stop();
            switch (imagetype)
            {
                case ImageType.alert:
                    this.image.Source = new BitmapImage(new Uri("/Lolana.Land.Zhjk;component/Resources/Images/message_alert.png", UriKind.Relative));   
                    break;
                case ImageType.error:
                    this.image.Source = new BitmapImage(new Uri("/Lolana.Land.Zhjk;component/Resources/Images/message_error.png", UriKind.Relative));   
                    break;
                case ImageType.loading:
                    this.image.Source = new BitmapImage(new Uri("/Lolana.Land.Zhjk;component/Resources/Images/message_loading.png", UriKind.Relative));
                    this.storyboard.Begin();
                    break;
                case ImageType.ok:
                    this.image.Source = new BitmapImage(new Uri("/Lolana.Land.Zhjk;component/Resources/Images/message_ok.png", UriKind.Relative));   
                    break;
            }
        }

        #endregion

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值