在子窗口中使用响应值

时间:2012-05-09 12:44:09

标签: c# silverlight xaml childwindow

我很难掌握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值),并说它是空值。如何在Initialise Component阶段使用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);

    }

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

1 个答案:

答案 0 :(得分:0)

我通过创建一个Keywords_Loaded void对其进行了排序。然后我就可以使用上一个表单中传入的值。