博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Silverlight Telerik控件学习:弹出窗口RadWindow
阅读量:7003 次
发布时间:2019-06-27

本文共 4360 字,大约阅读时间需要 14 分钟。

几乎所有的业务系统都有弹出窗口,典型场景有二种 :

1、简单的弹出一个对话框显示信息,比如下面这样:

2011051916361792.png

这个很简单,代码示例如下:

DialogParameters pars = new DialogParameters();            pars.Header = "信息";pars.Content = "Hello World";RadWindow.Alert(pars);

2、点击某条记录的“编辑”按钮,传入ID参数,弹出一个窗口,编辑保存后,将操作结果返回给父窗口

2011051916383264.png

这种场景下,要求:

a)弹出窗口能接受到父窗口传过来的参数

b)弹出窗口关闭时,父窗口要能区分出是通过什么操作关闭的(比如:是直接点击右上角的X按钮关的,还是点击“提交”按钮关的,或是点击“取消”按钮关的)

c)弹出窗关闭后,父窗口要能知道操作结果

示例代码如下:

弹出窗口Xaml部分:

用户名:
密码:
重复密码:
生日:
电子邮件:
电话号码:
手机号码:

弹出窗口Xaml.cs部分

using System;using System.Collections.Generic;using System.Windows;using Telerik.Windows.Controls;namespace Telerik.Sample{    public partial class PopWinUserReg : RadWindow    {        public PopWinUserReg()        {            InitializeComponent();            this.Loaded += new RoutedEventHandler(PopWinUserReg_Loaded);        }        void PopWinUserReg_Loaded(object sender, RoutedEventArgs e)        {            Dictionary
dicPars = this.Tag as Dictionary
; if (dicPars != null) { string id = dicPars["id"].ToString(); RadWindow.Alert("传入参数为:" + id); } } private void btnCancel_Click(object sender, RoutedEventArgs e) { this.DialogResult = false; this.Close(); } private void btnSubmit_Click(object sender, RoutedEventArgs e) { this.DialogResult = true; this.Tag = "回传给父窗口的值在这里!"; this.Close(); } }}

父窗口Xaml.cs部分:

using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Telerik.Windows.Controls;namespace Telerik.Sample{    public partial class FormInput : UserControl    {        PopWinUserReg win=null;        Dictionary
dicPars = new Dictionary
(); public FormInput() { InitializeComponent(); this.Loaded += new RoutedEventHandler(FormInput_Loaded); this.Unloaded += new RoutedEventHandler(FormInput_Unloaded); } void FormInput_Loaded(object sender, RoutedEventArgs e) { win = new PopWinUserReg(); win.Loaded += new RoutedEventHandler(win_Loaded); win.Closed += new EventHandler
(win_Closed); } void win_Closed(object sender, Windows.Controls.WindowClosedEventArgs e) { if (!e.DialogResult.HasValue) { RadWindow.Alert("直接关闭了弹出窗口!"); } else if (e.DialogResult.Value) { string result = win.Tag.ToString(); RadWindow.Alert("点击“提交”关闭的,传回来的值为:" + result); } else { RadWindow.Alert("点击“取消”关闭的!"); } } void win_Loaded(object sender, RoutedEventArgs e) { RadWindow.Alert("弹出窗口加载完成!"); } void FormInput_Unloaded(object sender, RoutedEventArgs e) { if (win != null) { win.Close(); win = null; } } private void btnReg_Click(object sender, RoutedEventArgs e) { #region 传参数到弹出窗口的Tag string PARAM_ID = "id"; if (dicPars.ContainsKey(PARAM_ID)) { dicPars.Remove(PARAM_ID); } dicPars.Add(PARAM_ID, 1); win.Tag = dicPars; #endregion win.ShowDialog(); } }}

转载地址:http://ybutl.baihongyu.com/

你可能感兴趣的文章