Silverlight学习笔记四(父窗体取得子窗体返回的值)
这里比较类似WinForm的对话框,与WebForm开发完全不一回事了。
新建Silverlight子窗口
新建Silverlight子窗口
大气象
using System;
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;
namespace SilverlightXML
{
public partial class ChildWindow1 : ChildWindow
{
public string resultVal = "空";//子窗体中设置public
public ChildWindow1()
{
InitializeComponent();
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
resultVal = txtInput.Text;//前台放个输入框
txtInput.Text = "";
this.DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
}
}
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;
namespace SilverlightXML
{
public partial class ChildWindow1 : ChildWindow
{
public string resultVal = "空";//子窗体中设置public
public ChildWindow1()
{
InitializeComponent();
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
resultVal = txtInput.Text;//前台放个输入框
txtInput.Text = "";
this.DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
}
}
父窗体中调用
大气象
using System;
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;
namespace SilverlightXML
{
public partial class TestPage3 : UserControl
{
ChildWindow1 child = new ChildWindow1();
public TestPage3()
{
InitializeComponent();
child.Closed += new EventHandler(Child_Close); //在父窗体注册子窗体的关闭事件
}
private void Child_Close(object sender, EventArgs e)
{
bool? result = child.DialogResult;
if (result.HasValue && result.Value)
{
MessageBox.Show("子窗体返回:" + child.resultVal);
}
}
private void btnChild_Click(object sender, RoutedEventArgs e)
{
child.Show();
}
}
}
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;
namespace SilverlightXML
{
public partial class TestPage3 : UserControl
{
ChildWindow1 child = new ChildWindow1();
public TestPage3()
{
InitializeComponent();
child.Closed += new EventHandler(Child_Close); //在父窗体注册子窗体的关闭事件
}
private void Child_Close(object sender, EventArgs e)
{
bool? result = child.DialogResult;
if (result.HasValue && result.Value)
{
MessageBox.Show("子窗体返回:" + child.resultVal);
}
}
private void btnChild_Click(object sender, RoutedEventArgs e)
{
child.Show();
}
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。