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. The SQL Server Service Broker for the current database is not enabled

    把一个数据恢复至另一个服务器上,出现了一个异常: The SQL Server Service Broker for the current database is not enabled, and ...

  2. 浅谈web网站架构演变过程

    前言 我们以javaweb为例,来搭建一个简单的电商系统,看看这个系统可以如何一步步演变.   该系统具备的功能:   用户模块:用户注册和管理 商品模块:商品展示和管理 交易模块:创建交易和管理 阶 ...

  3. Entity Framework 5.0 Code First全面学习

    摘自:http://blog.csdn.net/gentle_wolf/article/details/14004345 不贴图片了,太累. Code First 约定 借助 CodeFirst,可通 ...

  4. poj1789--最小生成树(prim)

    水题... 题目大意: 用一个7位的字符串代表一个编号,两个编号之间的distance代表这两个编号之间不同字母的个数.一个编号只能由另一个编号“衍生”出来,代价是这两个编号之间相应的distance ...

  5. 把生成的excel文件直接提供为下载页效果

    把php中的excel显示下载页下载到本地硬盘需要设置头信息: 代码: $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Ex ...

  6. 【python环境配置1】 环境变量与常用模块

    1. 安装python27 2. 配置环境变量 找到python.exe的安装文件夹,复制路径(C:\python27\Arcgis10.2): 将该路径粘贴到 "控制面板\系统和安全\系统 ...

  7. 工业串口和网络软件通讯平台(SuperIO 2.1)更新发布

    SuperIO 2.1下载 一.SuperIO 的特点: 1)    能够很快的构建自己的通讯平台软件,包括主程序. 2)   设备模块化开发,通过配制文件挂载,即可在平台软件下运行. 3)   设备 ...

  8. apache反向代理

    正向代理是客户端发送请求给代理服务器,代理服务器将请求发给实际处理的服务器 反向代理是客户端发送请求给服务器(实际上是个代理服务器),服务器将请求发给实际处理的服务器 情景 在一台服务器上开了apac ...

  9. 用childNodes获取子元素 换行会产生一个子元素

    <div id='div1'> <div id='div2'> <div id='div3'></div> </div> <div c ...

  10. 很漂亮的用户登录界面HTML模板

    效果预览:http://keleyi.com/keleyi/phtml/divcss/21.htm HoverTree开源项目实现了分层后,准备实现管理员后台登录,这里先把登录界面的HTML模板整理好 ...