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

来源:互联网 发布:win7 kali linux双系统 编辑:程序博客网 时间:2024/09/21 09:29
 

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

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

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

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

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

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

 

这种场景下,要求:

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

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

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

示例代码如下:

弹出窗口Xaml部分:

 
01<telerik:RadWindow x:Class="Telerik.Sample.PopWinUserReg"
02    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
03    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
04    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
05    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
06    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
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    publicpartial classPopWinUserReg : RadWindow
09    {
10        publicPopWinUserReg()
11        {
12            InitializeComponent();
13            this.Loaded +=new RoutedEventHandler(PopWinUserReg_Loaded);
14        }
15  
16        voidPopWinUserReg_Loaded(objectsender, RoutedEventArgs e)
17        {
18            Dictionary<string, Object> dicPars =this.Tag as Dictionary<string,object>;
19            if(dicPars != null
20            {
21                stringid = dicPars["id"].ToString();
22                RadWindow.Alert("传入参数为:"+ id);
23            }
24        }
25  
26        privatevoid btnCancel_Click(objectsender, RoutedEventArgs e)
27        {
28            this.DialogResult =false;
29            this.Close();
30        }
31  
32        privatevoid btnSubmit_Click(objectsender, 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    publicpartial classFormInput : UserControl
18    {
19        PopWinUserReg win=null;
20        Dictionary<string, Object> dicPars =new Dictionary<string,object>();
21  
22        publicFormInput()
23        {
24            InitializeComponent();
25  
26            this.Loaded +=new RoutedEventHandler(FormInput_Loaded);
27            this.Unloaded +=new RoutedEventHandler(FormInput_Unloaded);
28        }
29  
30        voidFormInput_Loaded(objectsender, 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        voidwin_Closed(objectsender, Windows.Controls.WindowClosedEventArgs e)
38        {
39            if(!e.DialogResult.HasValue) 
40            {
41                RadWindow.Alert("直接关闭了弹出窗口!");
42            }
43            elseif (e.DialogResult.Value)
44            {
45                stringresult = win.Tag.ToString();
46                RadWindow.Alert("点击“提交”关闭的,传回来的值为:"+ result);
47            }
48            else 
49            {
50                RadWindow.Alert("点击“取消”关闭的!");
51            }
52              
53              
54        }
55  
56        voidwin_Loaded(objectsender, RoutedEventArgs e)
57        {
58            RadWindow.Alert("弹出窗口加载完成!");
59        }
60  
61        voidFormInput_Unloaded(objectsender, RoutedEventArgs e)
62        {
63            if(win != null
64            {
65                win.Close();
66                win =null;
67            }
68        }
69  
70        privatevoid btnReg_Click(objectsender, RoutedEventArgs e)
71        {
72            #region 传参数到弹出窗口的Tag
73            stringPARAM_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
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原创粉丝点击