在子窗口中使用响应值

本文关键字:响应 窗口 | 更新日期: 2023-09-27 18:33:48

我很难掌握 Silverlight 如何使用来自 Web 服务的异步响应。我已经宣布——

public partial class Users : Page
{
    public string PID;

然后使用-

 if
 {
 WebService.Service1SoapClient client = new WebService.Service1SoapClient();
 string profile = System.Convert.ToString(((ListBoxItem)listBox1.SelectedItem).Content);
 client.pidReturnCompleted += new EventHandler<pidReturnCompletedEventArgs>(client_pidReturnCompleted);
 client.pidReturnAsync(USERID, profile);
 }
 Else
 {
 KeyWords keywords = new KeyWords();
 keywords.textBox3.Text = PID;
 keywords.Show();

其中 PID-

void client_pidReturnCompleted(object sender, pidReturnCompletedEventArgs e)
    {
        PID = e.Result;
    }

然后,我需要在关键字子窗口的Initialise Component部分中使用此PID,但是当窗口加载时,它不会及时获取textBox.Text(PID值),并说它是null。如何在初始化组件阶段使用 PID?所以在关键字窗口中-

public KeyWords()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(KeyWords_Loaded);
        WebService.Service1SoapClient client = new WebService.Service1SoapClient();
        client.userKeywordsCompleted += new EventHandler<userKeywordsCompletedEventArgs>(client_userKeywordsCompleted);
        client.userKeywordsAsync(PID);
    }

其中- Public Int PID = textBox3.Text //this is where the value from the previous window is passed in.

在子窗口中使用响应值

我通过创建一个Keywords_Loaded空白来对其进行排序。然后,我能够使用从上一个表单传入的值。