Silverlight Telerik控件学习:弹出窗口RadWindow

 

Silverlight Telerik控件学习:弹出窗口RadWindow

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

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

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

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

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

 

这种场景下,要求:

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

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

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

示例代码如下:

弹出窗口Xaml部分:

 
01<telerik:RadWindow x:Class="Telerik.Sample.PopWinUserReg"
07    mc:Ignorable="d"
08    d:DesignHeight="480" d:DesignWidth="640" WindowStartupLocation="CenterScreen" Header="会员注册" Padding="10" Width="640" Height="300" ResizeMode="NoResize">
09      
10    <Grid x:Name="LayoutRoot" Background="White">
11        <Grid.RowDefinitions>
12            <RowDefinition Height="30" />
13            <RowDefinition Height="30" />
14            <RowDefinition Height="30" />
15            <RowDefinition Height="30" />
16            <RowDefinition Height="30" />
17            <RowDefinition Height="30" />
18            <RowDefinition Height="30" />
19            <RowDefinition Height="Auto" MinHeight="10" />
20            <RowDefinition Height="30" />
21        </Grid.RowDefinitions>
22        <Grid.ColumnDefinitions>
23            <ColumnDefinition Width="100" />
24            <ColumnDefinition Width="*" />
25        </Grid.ColumnDefinitions>
26          
27        <TextBlock VerticalAlignment="Center" TextAlignment="Right">用户名:</TextBlock>
28        <telerik:RadMaskedTextBox Grid.Column="1" Grid.Row="0"  Name="txtUserName" VerticalAlignment="Center" Mask="aaaaaaaaaa"  Margin="0,0,10,0" />
29        <TextBlock VerticalAlignment="Center" TextAlignment="Right" Grid.Row="1">密码:</TextBlock>
30        <telerik:RadMaskedTextBox Grid.Column="1" Grid.Row="1"  Name="txtPassWord" VerticalAlignment="Center" Margin="0,0,10,0" />
31        <TextBlock VerticalAlignment="Center" TextAlignment="Right" Grid.Row="2">重复密码:</TextBlock>
32        <telerik:RadMaskedTextBox Grid.Column="1" Grid.Row="2"  Name="txtPassWord2" VerticalAlignment="Center" Margin="0,0,10,0" />
33        <TextBlock VerticalAlignment="Center" TextAlignment="Right" Grid.Row="3">生日:</TextBlock>
34        <telerik:RadMaskedTextBox Grid.Column="1" Grid.Row="3"  Name="txtBirthday" VerticalAlignment="Center" Margin="0,0,10,0" />
35        <TextBlock VerticalAlignment="Center" TextAlignment="Right" Grid.Row="4">电子邮件:</TextBlock>
36        <telerik:RadMaskedTextBox Grid.Column="1" Grid.Row="4"  Name="txtEmail" VerticalAlignment="Center" Margin="0,0,10,0" />
37        <TextBlock VerticalAlignment="Center" TextAlignment="Right" Grid.Row="5">电话号码:</TextBlock>
38        <telerik:RadMaskedTextBox Grid.Column="1" Grid.Row="5"  Name="txtTel" VerticalAlignment="Center" Margin="0,0,10,0" />
39        <TextBlock VerticalAlignment="Center" TextAlignment="Right" Grid.Row="6">手机号码:</TextBlock>
40        <telerik:RadMaskedTextBox Grid.Column="1" Grid.Row="6"  Name="txtMobile" VerticalAlignment="Center" Margin="0,0,10,0" />
41  
42        <StackPanel Grid.Row="8" Grid.Column="1" Orientation="Horizontal" Height="22">
43        <telerik:RadButton Content="提 交"  Width="70" Name="btnSubmit" Click="btnSubmit_Click" />
44        <telerik:RadButton Content="取 消"  Width="70" Margin="10,0,0,0" Name="btnCancel" Click="btnCancel_Click" />
45        </StackPanel>
46    </Grid>
47</telerik:RadWindow>

弹出窗口Xaml.cs部分

 
01using System;
02using System.Collections.Generic;
03using System.Windows;
04using Telerik.Windows.Controls;
05  
06namespace Telerik.Sample
07{
08    public partial class PopWinUserReg : RadWindow
09    {
10        public PopWinUserReg()
11        {
12            InitializeComponent();
13            this.Loaded += new RoutedEventHandler(PopWinUserReg_Loaded);
14        }
15  
16        void PopWinUserReg_Loaded(object sender, RoutedEventArgs e)
17        {
18            Dictionary<string, Object> dicPars = this.Tag as Dictionary<string, object>;
19            if (dicPars != null
20            {
21                string id = dicPars["id"].ToString();
22                RadWindow.Alert("传入参数为:" + id);
23            }
24        }
25  
26        private void btnCancel_Click(object sender, RoutedEventArgs e)
27        {
28            this.DialogResult = false;
29            this.Close();
30        }
31  
32        private void btnSubmit_Click(object sender, RoutedEventArgs e)
33        {
34            this.DialogResult = true;
35            this.Tag = "回传给父窗口的值在这里!";
36            this.Close();
37        }
38    }
39}

父窗口Xaml.cs部分:

 
01using System;
02using System.Collections;
03using System.Collections.Generic;
04using System.Linq;
05using System.Net;
06using System.Windows;
07using System.Windows.Controls;
08using System.Windows.Documents;
09using System.Windows.Input;
10using System.Windows.Media;
11using System.Windows.Media.Animation;
12using System.Windows.Shapes;
13using Telerik.Windows.Controls;
14  
15namespace Telerik.Sample
16{
17    public partial class FormInput : UserControl
18    {
19        PopWinUserReg win=null;
20        Dictionary<string, Object> dicPars = new Dictionary<string, object>();
21  
22        public FormInput()
23        {
24            InitializeComponent();
25  
26            this.Loaded += new RoutedEventHandler(FormInput_Loaded);
27            this.Unloaded += new RoutedEventHandler(FormInput_Unloaded);
28        }
29  
30        void FormInput_Loaded(object sender, RoutedEventArgs e)
31        {
32            win = new PopWinUserReg();
33            win.Loaded += new RoutedEventHandler(win_Loaded);
34            win.Closed += new EventHandler<Windows.Controls.WindowClosedEventArgs>(win_Closed);
35        }
36  
37        void win_Closed(object sender, Windows.Controls.WindowClosedEventArgs e)
38        {
39            if (!e.DialogResult.HasValue) 
40            {
41                RadWindow.Alert("直接关闭了弹出窗口!");
42            }
43            else if (e.DialogResult.Value)
44            {
45                string result = win.Tag.ToString();
46                RadWindow.Alert("点击“提交”关闭的,传回来的值为:" + result);
47            }
48            else 
49            {
50                RadWindow.Alert("点击“取消”关闭的!");
51            }
52              
53              
54        }
55  
56        void win_Loaded(object sender, RoutedEventArgs e)
57        {
58            RadWindow.Alert("弹出窗口加载完成!");
59        }
60  
61        void FormInput_Unloaded(object sender, RoutedEventArgs e)
62        {
63            if (win != null
64            {
65                win.Close();
66                win = null;
67            }
68        }
69  
70        private void btnReg_Click(object sender, RoutedEventArgs e)
71        {
72            #region 传参数到弹出窗口的Tag
73            string PARAM_ID = "id";
74            if (dicPars.ContainsKey(PARAM_ID)) 
75            {
76                dicPars.Remove(PARAM_ID);
77            }
78            dicPars.Add(PARAM_ID, 1);
79            win.Tag = dicPars;
80            #endregion
81            win.ShowDialog();
82        }
83    }
84}

作者: 菩提树下的杨过
出处: http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值