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. PHP中json_encode后中文乱码的解决方案

    <?php header("Content-Type:text/html;charset=utf-8;"); $arr = array ('Version_code'=> ...

  2. 你不知道的HttpHandler相关知识

    一.关于IHttpHandler.IsReusable 很多人不明白,这哥们到底干嘛的,估计是微软最初的一个想法--让一个对象可以一直不断地被重复使用 ,但这个想法不成熟,会带来很多隐藏问题,一个对象 ...

  3. C# 热敏打印机 Socket 网络链接 打印 图片 (一)

    using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using Syste ...

  4. 写个C#命令行参数解析的小工具

    最近测试工作做的比较多因此时常要创建一些控制台类型的应用程序.因为程序有不同的参数开关,需要在程序启动的时候通过命令行来给程序传递各种开关和参数.直接操作args有些不方便,所以就写了个解析参数的小工 ...

  5. ym—— Android网络框架Volley(体验篇)

    VolleyGoogle I/O 2013推出的网络通信库,在volley推出之前我们一般会选择比较成熟的第三方网络通信库,如: android-async-http retrofit okhttp ...

  6. centos安装禅道的步骤

    1.下载 XAMPP 套件: https://sourceforge.net/projects/xampp/files/XAMPP%20Linux/stats/timeline  下载的文件是 xam ...

  7. HTTP协议详解

    Author :Jeffrey 引言 HTTP 是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和 扩展. ...

  8. VMWare 安装 Mac OS X10.10 Yosemite

    OS X Yosemite 新功能特性 Mac OS X10.10 GM3|OS X 10.10 Yosemite 正式版下载 如何在虚拟机中安装苹果mac系统图示说明 vm10虚拟机安装Mac OS ...

  9. windows下新安装的mysql修改root password问题

    常用步骤: 1. 在my.ini中的mysqld下添加一行 skip-grant-tables 2.重启mysql后直接进入后,用SQL直接修改password列: C:\> net stop ...

  10. ul ol di三者区别

    1.ul是无序列表,也就是说没有排列限制可以随意加li: <ul> <li>可以随意放置</li> <li>可以随意放置</li> < ...