WPF 提示框、确认框、确认输入框
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 提示框、确认框、确认输入框的更多相关文章
- jquery仿alert提示框、confirm确认对话框、prompt带输入的提示框插件[附实例演示]
jquery仿alert提示框.confirm确认对话框.prompt带输入的提示框插件实例演示 第一步:引入所需要的jquery插件文件: http://www.angelweb.cn/Inc/eg ...
- JS_Window-三种消息框:警告框、确认框、提示框、页面显示时间-计时-延时
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...
- 20160622001 GridView 删除列 用模板实现删除时提示确认框
GridView在使用CommandField删除时弹出提示框,在.net2005提供的GridView中我们可以直接添加一个 CommandField删除列:<asp:CommandField ...
- GridView使用CommandField删除列实现删除时提示确认框
在.net2005提供的GridView中我们可以直接添加一个CommandField删除列完后在它的RowDeleting事件中完成删除 GridView在使用CommandField删除时弹出提示 ...
- js三种消息框总结-警告框、确认框、提示框
js消息框类别:警告框.确认框.提示框 警告框:alert("文本"); 确认框:confirm("文本"); 提示框:prompt("文本" ...
- JavaScript 中创建三种消息框:警告框、确认框、提示框。
网址:http://www.w3school.com.cn/js/js_popup.asp 警告框 警告框经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行操作. 语 ...
- JavaScript 消息框,警告框,确认框,提示框
1.警告框 警告框经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行操作. 语法: alert("文本") 2.确认框 确认框用于使用户可以验证或 ...
- js创建弹框(提示框,待确认框)
;;} html,body{text-size-adjust:none;-webkit-text-size-adjust:none;-webkit-user-select:none;} a{color ...
- JS基础 浏览器弹出的三种提示框(提示信息框、确认框、输入文本框)
浏览器的三种提示框 alert() //提示信息框 confirm() //提示确认框 prompt() //提示输入文本框 1.alert( ) 提示信息框 <script> alert ...
随机推荐
- 教你快速高效接入SDK——服务器端支付回调的处理方式
转载自:http://blog.csdn.net/chenjie19891104/article/details/48321427今天着重把之前渠道服务器端SDK的时候,遇到的一个蛋疼的问题给解决了. ...
- CSS-float详解,深入理解clear:both[转+部分原创]
首先要知道,div是块级元素,在页面中独占一行,自上而下排列,也就是传说中的流. 可以看出,即使div1的宽度很小,页面中一行可以容下div1和div2,div2也不会排在div1后边,因为div元素 ...
- 详解Javascript的继承实现(二)
上文<详解Javascript的继承实现>介绍了一个通用的继承库,基于该库,可以快速构建带继承关系和静态成员的javascript类,好使用也好理解,额外的好处是,如果所有类都用这种库来构 ...
- 谈I/O模型
一个IO操作涉及两个系统对象: 调用这个IO的用户Process/Thread 系统内核 - System Kernel 一个具体的Read操作包括两个阶段: 内核等待数据准备就绪:Waiting f ...
- Linux-网络连接-(VMware与CentOS)
VMware虚拟机中安装CentOS,进行网络连接,分为两步,内网连接,与外网连接. 前提: 当你正确安装VMware后,网络适配器会增加2个新的网卡:(可在设备管理器->网络适配器中查看) 第 ...
- linux下的目录结构和内容
用了这么长时间linux系统,有时候哪个文件应该在哪还是不知道的,所以对于根下的目录结构记下: /bin bin是Binary的缩写.这个目录存放着最经常使用的命令. /boot这里存放的是启动Lin ...
- linux下安装mysql
下载Mysql包 因为mysql比较大,我们不能像安装nginx和php那样,通过下载源码,编译成二进制安装.mysql安装比php和nginx稍微麻烦一点. 这里mysql我们直接下载编译好的二进制 ...
- Linux Cmd Tool 系列之—script & scriptreplay
Intro Sometime we want to record cmd and outputs in the interactive shell sessions. However history ...
- 使用AngularJS实现简单:全选和取消全选功能
这里用到AngularJS四大特性之二----双向数据绑定 注意:没写一行DOM代码!这就是ng的优点,bootstrap.css为了布局,JS代码也只是简单创建ng模块和ng控制器 效果: < ...
- Javascript中构造函数与new命令
典型的面向对象编程语言(比如C++和Java),存在“类”(class)这个概念.所谓“类”就是对象的模板,对象就是“类”的实例.但是,在JavaScript语言的对象体系,不是基于“类”的,而是基于 ...