1、提示框

分为提示、异常、失败、成功几种类型

方法:

        /// <summary>
/// 弹出提示
/// 标题:提示
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowInfoMessageBox(string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageInfoStyle"] as Style, "提示");
}
/// <summary>
/// 弹出提示
/// 标题:异常
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowExceptionMessageBox(string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageInfoStyle"] as Style, "异常");
}
/// <summary>
/// 弹出提示
/// 标题:失败
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowErrorMessageBox(string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageErrorStyle"] as Style, "失败");
}
/// <summary>
/// 弹出提示
/// 标题:成功
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowSuccessMessageBox(string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageSuccessStyle"] as Style, "成功");
} private static void AlertRadWindow(ContentControl owner, string strContent, Style style, string header)
{
RadWindow.Alert(new DialogParameters()
{
Owner = owner,
Content = new TextBlock() { Text = strContent, TextWrapping = TextWrapping.Wrap, VerticalAlignment = VerticalAlignment.Center },
ContentStyle = style,
Header = header,
});
}

样式:

    <Style x:Key="MessageInfoStyle" TargetType="{x:Type telerik:RadAlert}">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="MinWidth" Value="200"/>
<Setter Property="Width" Value="auto"/>
<Setter Property="MaxWidth" Value="400"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadAlert}">
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" MinHeight="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image x:Name="Icon" Grid.Row="0" Grid.Column="0" Margin="8" VerticalAlignment="Center" Height="30" Source="..\..\Images\Caption\tishi .png"/>
<ContentPresenter x:Name="AlertText" Grid.Row="0" Grid.Column="1" Margin="0,8,8,8" VerticalAlignment="Center"/>
<Border x:Name="HorizontalRule" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" BorderBrush="Gainsboro" Height="2" BorderThickness="0 0 0 1"/>
<telerik:RadButton x:Name="OK" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Right" Margin="8,5,8,5" MinWidth="70" Content="确定"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MessageErrorStyle" TargetType="{x:Type telerik:RadAlert}">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="MinWidth" Value="200"/>
<Setter Property="Width" Value="auto"/>
<Setter Property="MaxWidth" Value="400"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadAlert}">
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" MinHeight="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image x:Name="Icon" Grid.Row="0" Grid.Column="0" Margin="8" VerticalAlignment="Center" Height="30" Source="..\..\Images\Caption\error.png"/>
<ContentPresenter x:Name="AlertText" Grid.Row="0" Grid.Column="1" Margin="0,8,8,8" VerticalAlignment="Center"/>
<Border x:Name="HorizontalRule" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" BorderBrush="Gainsboro" Height="2" BorderThickness="0 0 0 1"/>
<telerik:RadButton x:Name="OK" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Right" Margin="8,5,8,5" MinWidth="70" Content="确定"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MessageSuccessStyle" TargetType="{x:Type telerik:RadAlert}">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="MinWidth" Value="200"/>
<Setter Property="Width" Value="auto"/>
<Setter Property="MaxWidth" Value="400"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadAlert}">
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" MinHeight="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image x:Name="Icon" Grid.Row="0" Grid.Column="0" Margin="8" VerticalAlignment="Center" Height="30" Source="..\..\Images\Caption\success.png"/>
<ContentPresenter x:Name="AlertText" Grid.Row="0" Grid.Column="1" Margin="0,8,8,8" VerticalAlignment="Center"/>
<Border x:Name="HorizontalRule" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" BorderBrush="Gainsboro" Height="2" BorderThickness="0 0 0 1"/>
<telerik:RadButton x:Name="OK" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Right" Margin="8,5,8,5" MinWidth="70" Content="确定"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

2、确认框

后台方法:

/// <summary>
/// 确认对话框
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="onClosed">关闭事件 案例:new EventHandler WindowClosedEventArgs(OnClosed))</param>
/// <param name="okButtonContent">确定按钮内容</param>
/// <param name="cancelButtonContent">取消按钮内容</param>
public static void ShowConfirmMessageBox(string strContent, EventHandler<WindowClosedEventArgs> onClosed, string okButtonContent, string cancelButtonContent)
{
Style style = Application.Current.Resources["MessageConfirmStyle"] as Style;
RadWindow.Confirm(new DialogParameters()
{
Owner = Application.Current.MainWindow,
Header = "确认",
ContentStyle = style,
Content = new TextBlock() { Text = strContent, TextWrapping = TextWrapping.Wrap, VerticalAlignment = VerticalAlignment.Center },
Closed = onClosed,
OkButtonContent = okButtonContent,
CancelButtonContent = cancelButtonContent,
});
}

样式设置:

    <Style x:Key="MessageConfirmStyle" TargetType="{x:Type telerik:RadConfirm}">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="MinWidth" Value="200"/>
<Setter Property="Width" Value="auto"/>
<Setter Property="MaxWidth" Value="400"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadConfirm}">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" MinHeight="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image x:Name="Icon" Grid.Row="0" Grid.Column="0" Margin="8" VerticalAlignment="Center" Height="30" Source="..\..\Images\Caption\help.png"/>
<ContentPresenter x:Name="AlertText" Grid.Row="0" Grid.Column="1" Margin="0,8,8,8" VerticalAlignment="Center"/> <Border x:Name="HorizontalRule" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" BorderBrush="Gainsboro" Height="2" BorderThickness="0 0 0 1"/> <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="90"></ColumnDefinition>
</Grid.ColumnDefinitions>
<telerik:RadButton x:Name="OK" HorizontalAlignment="Right" Margin="8,5,8,5" MinWidth="70" Grid.Column="0" />
<telerik:RadButton x:Name="Cancel" HorizontalAlignment="Right" Margin="8,5,8,5" MinWidth="70" Grid.Column="1" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

3、确认输入对话框

方法:

        /// <summary>
/// 输入确认对话框
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="onClosed">关闭事件 案例:new EventHandler WindowClosedEventArgs(OnClosed))</param>
/// <param name="okButtonContent">确定按钮内容</param>
/// <param name="cancelButtonContent">取消按钮内容</param>
public static void ShowPromptMessageBox(string strContent, EventHandler<WindowClosedEventArgs> onClosed, string okButtonContent, string cancelButtonContent)
{
DialogParameters dialogParameters = new DialogParameters();
dialogParameters.Owner = Application.Current.MainWindow;
dialogParameters.Header = "确认";
dialogParameters.Content = strContent;
dialogParameters.OkButtonContent = okButtonContent;
dialogParameters.CancelButtonContent = cancelButtonContent;
dialogParameters.Closed = onClosed;
RadWindow.Prompt(dialogParameters);
}

样式没有,可以自己自定义一个~

PS:可以将样式放入App.xaml中,然后后台通过 Application.Current.Resources就可以获取了。当然也可以将这些样式封装成UserCotrol,再应用也不错。

WPF 提示框、确认框、确认输入框的更多相关文章

  1. jquery仿alert提示框、confirm确认对话框、prompt带输入的提示框插件[附实例演示]

    jquery仿alert提示框.confirm确认对话框.prompt带输入的提示框插件实例演示 第一步:引入所需要的jquery插件文件: http://www.angelweb.cn/Inc/eg ...

  2. JS_Window-三种消息框:警告框、确认框、提示框、页面显示时间-计时-延时

    1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...

  3. 20160622001 GridView 删除列 用模板实现删除时提示确认框

    GridView在使用CommandField删除时弹出提示框,在.net2005提供的GridView中我们可以直接添加一个 CommandField删除列:<asp:CommandField ...

  4. GridView使用CommandField删除列实现删除时提示确认框

    在.net2005提供的GridView中我们可以直接添加一个CommandField删除列完后在它的RowDeleting事件中完成删除 GridView在使用CommandField删除时弹出提示 ...

  5. js三种消息框总结-警告框、确认框、提示框

    js消息框类别:警告框.确认框.提示框 警告框:alert("文本"); 确认框:confirm("文本"); 提示框:prompt("文本" ...

  6. JavaScript 中创建三种消息框:警告框、确认框、提示框。

    网址:http://www.w3school.com.cn/js/js_popup.asp 警告框 警告框经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行操作. 语 ...

  7. JavaScript 消息框,警告框,确认框,提示框

    1.警告框 警告框经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行操作. 语法: alert("文本") 2.确认框 确认框用于使用户可以验证或 ...

  8. js创建弹框(提示框,待确认框)

    ;;} html,body{text-size-adjust:none;-webkit-text-size-adjust:none;-webkit-user-select:none;} a{color ...

  9. JS基础 浏览器弹出的三种提示框(提示信息框、确认框、输入文本框)

    浏览器的三种提示框 alert() //提示信息框 confirm() //提示确认框 prompt() //提示输入文本框 1.alert( ) 提示信息框 <script> alert ...

随机推荐

  1. SQL Server基础之存储过程

      简单来说,存储过程就是一条或者多条sql语句的集合,可视为批处理文件,但是其作用不仅限于批处理.本篇主要介绍变量的使用,存储过程和存储函数的创建,调用,查看,修改以及删除操作. 一:存储过程概述 ...

  2. 20个非常棒的jQuery倒计时脚本

    使用jQuery倒计时插件可能是最简单最好的方式添加动态和交互式倒数计时器到您的网站上.我相信你已经注意到了,例如倒计时功能运行网站,显示倒计时,直到一个大事件.当网站正在维护,告诉用户什么时候回来, ...

  3. linux源码分析(二)-启动过程

    前置:这里使用的linux版本是4.8,x86体系. 这篇是 http://home.ustc.edu.cn/~boj/courses/linux_kernel/1_boot.html 的学习笔记. ...

  4. javascript异步编程的前世今生,从onclick到await/async

    javascript与异步编程 为了避免资源管理等复杂性的问题, javascript被设计为单线程的语言,即使有了html5 worker,也不能直接访问dom. javascript 设计之初是为 ...

  5. 匿名方法与Lambda表达式

    1.匿名方法 在学习委托时,我们知道委托实例至少要绑定一个方法才能使用,而调用委托实际上是调用了它所关联地方法.一般来说,需要定义一个与委托签名相符的方法,并使之与委托变量关联.如以下代码: Acti ...

  6. C#动态编译

    C#提供了DynamicObject和IDynamicMetaObjectProvider两种方式实现动态类型,动态类型的好处是类型的公有接口可以在运行时改变. 创建动态类型最简单的方法就是继承Dyn ...

  7. button 按钮,结合onclick事件,验证和提交表单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. nginx配置多个虚拟主机vhost

    在nginx下配置虚拟主机vhost非常方便.主要在nginx的配置文件nginx.conf中添加一个server即可 比如我想配置两个虚拟主机,通过域名linux.com和linux2.com访问, ...

  9. ABP 初探 之基于EasyUI的CURD

    结束了天天加班的项目,项目虽然结束,但还是有点小问题,只能在后期优化当中完成了,本次做项目采用了,MVC.Webapi.Entityframework,在园了里看到了有关ABP的介绍,同样ABP也是最 ...

  10. link与@import的区别

    我们都知道link与@import都可以引入css样式表,那么这两种的区别是什么呢?先说说它们各自的链接方式,然后说说它们的区别~~~ link链入的方式: <link rel="st ...