新建自定义控件:
<UserControl x:Class="EasySL.UI.Dialogs.Popupborder" 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="300" d:DesignWIDth="400"> <UserControl.Resources> <Storyboard x:name="myStoryboard"> <DoubleAnimation Storyboard.Targetname="LayoutRoot" Storyboard.TargetProperty="Opacity" From="1.0" To="0" Duration="0:0:1" autoReverse="True" /> </Storyboard> </UserControl.Resources> <GrID x:name="LayoutRoot" > <!--<border Background="#FFCC0D0D" borderThickness="0" CornerRadius="5">--> <border borderThickness="0" CornerRadius="5"> <border.Background> <linearGradIEntBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradIEntStop color="#FF27A3D7" Offset="0.51"/> <GradIEntStop color="#FF76C2E1" Offset="0.004"/> <GradIEntStop color="#FF27A3D7" Offset="1"/> </linearGradIEntBrush> </border.Background> <border.Effect> <DropShadowEffect BlurRadius="10" color="#FFCC0D0D" ShadowDepth="0"/> </border.Effect> <TextBlock x:name="txtMessage" HorizontalAlignment="Center" margin="10" VerticalAlignment="Center" FontSize="28" Foreground="White" FontFamily="Comic Sans MS" >This is a Simple Example</TextBlock> </border> </GrID></UserControl>
封装重构,新建MessageBoxHelper类:
using System;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.Ink;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;using System.windows.Controls.Primitives;using EasySL.UI.Dialogs;namespace EasySL.UI.Common{ public class MessageBoxHelper { #region 提示消息 /// <summary> /// d出提示消息标题为提示,按钮为确定 /// </summary> /// <param name="msg"></param> public static voID ShowMessage(string msg) { //ShowFrIEndMessage(msg,"提示",MessageBoxbutton.OK); Popupborder pborder = new Popupborder(); pborder.txtMessage.Text = " " + msg + " "; pborder.UpdateLayout(); Popup popUp = new Popup(); popUp.Child = pborder; pborder.myStoryboard.Completed += delegate { popUp.IsOpen = false; }; pborder.myStoryboard.Begin(); popUp.InvokeOnLayoutUpdated(() => { popUp.margin = new Thickness( (App.Current.Host.Content.ActualWIDth - pborder.ActualWIDth) / 2,(App.Current.Host.Content.ActualHeight - pborder.ActualHeight) / 2,0); System.Threading.Timer timer = new System.Threading.Timer( (state) => { popUp.dispatcher.BeginInvoke(() => { popUp.IsOpen = false; }); },null,500,500); }); popUp.IsOpen = true; } /// <summary> /// d出提示消息按钮为确定 /// </summary> /// <param name="msg"></param> public static voID ShowMessage(string msg,string Title) { ShowMessage(msg,Title,MessageBoxbutton.OK); } /// <summary> /// d出提示消息 /// </summary> /// <param name="msg"></param> public static voID ShowMessage(string msg,string Title,MessageBoxbutton buttons) { MessageBox.Show(msg,buttons); } #endregion }}总结
以上是内存溢出为你收集整理的silverlight 利用poup和定时器写自动消失的框全部内容,希望文章能够帮你解决silverlight 利用poup和定时器写自动消失的框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)