Silverlight弹出层(转载)

ChildWindow为Silverlight中的弹出子窗口

可以在项目新建子窗口文件:

Silverlight之ChildWindow用法

 

相互传值:

 

//父窗体向子窗体传值,需要在ChildWindow中构造函数进行传值
ChildWindowTest ChildWindow = new ChildWindowTest("ChildWindow用法:父页,子页相互传值");


Silverlight之ChildWindow用法 

Silverlight之ChildWindow用法

 

父窗口接子窗体方法如下:

首先在父窗体构造函数中写下如下代码:

 //注册弹出窗口的关闭事件:
ChildWindow.Closed += new EventHandler(ChildWindow_Closed); 

//弹出子页函数:
void ChildWindow_Closed(object sender, EventArgs e)
{
      //子页的返回值
      string ReturnValue = ChildWindow.ReturnValue;

      MessageBox.Show(ReturnValue);
}

 

//显示子页代码:

ChildWindow.show();

 

子页代码如下:
    public partial class ChildWindowTest : ChildWindow
    {
        //返回值
        public string ReturnValue { get; set; }

        public ChildWindowTest(string TextS)
        {
          
            InitializeComponent();
            //父类传过来的值
            this.Text1.Text = TextS;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            ReturnValue = "返回值为:OK";

            //this.DialogResult  调用其属性时,会自动触发本页面的Close()事件
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            ReturnValue = "返回值为:Cancel";

            //this.DialogResult  调用其属性时,会自动触发本页面的Close()事件
            this.DialogResult = false;
        }
    }


 

 


 

posted @ 2013-06-25 16:06  fang_beny  阅读(242)  评论(0编辑  收藏  举报