Search code examples
c#silverlighttextboxchildwindow

Passing value into textbox


I am using Silverlight, and passing a value into a textbox in a childwindow,

the textBox1_TextChanged event should fire a webservice call that should populate a listbox on the childwindow, however for some reason when the child window loads, the text box has the value passed into it as desired, but for some reason the TextChanged event is not firing?

Is there any specific reason for this?

Here is the change event -

private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
    {
        WebService.Service1SoapClient client = new WebService.Service1SoapClient();
        client.PRSHListCompleted += new EventHandler<PRSHListCompletedEventArgs>(client_PRSHListCompleted);
        client.PRSHListAsync(System.Convert.ToInt16(textBox1.Text));

        textBox2.Text = "OK"; //I did this to test if I was getting to the event and it failed.
    }

I pass in textBox1.Text from the parent window here-

Settings set = new Settings();
set.textBox1.Text = System.Convert.ToString(PRSID);

set.Show();

Where set is the child window.

This is the XAML for the text box -

<TextBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="12,13,0,0" Name="textBox1" VerticalAlignment="Top" Width="28" TextChanged="textBox1_TextChanged" />

Solution

  • You can set the textBox1.Text right after the Settings.Loaded event is fired and all XAML event subscriptions are made.

    So try this one:

    Settings set = new Settings();
    set.Loaded += (o, args) =>
    {
        //set.Dispatcher.BeginInvoke(() =>
        //{
        set.textBox1.Text = System.Convert.ToString(PRSID);
        //});
    };
    
    set.Show();