Link to home
Start Free TrialLog in
Avatar of baz86
baz86

asked on

Pass Data from Parent window to query in Child Window

Hi experts..

I have a silverlight page which has a list of users (for example) and I am trying to get it so that when i click on it, a child window appears and within that window there is another datagrid that is to be populated with data from tables based on the user i selected from the list box.

I am having difficultly passing userID to the wcf query behind the datagrid in the child window. The datagrid returns empty.

could you please correct me in where i am going wrong please..the code i have is below

**this code i have in the MainPage.xaml for the listbox_selected changed event.**
            ServiceReference1.site test = (site)ListBox1.SelectedItem;
            ChildShowDeviceResults cmod = new ChildShowDeviceResults();
           
            cmod.DataContext = test;
            cmod.Show();

**in the ChildWindow I have placed a textbox just to see if i can bind a value to it from the datacontext from the MainPage. When i load the childwindow, i can see taht the textbox shows the actual id of the user i selected, but then when i try to run the Page_Loaded event, the query doesnt seem to take the value into its parameters**

 private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            _ServiceClient client = new _ServiceClient();
            client.getResultsByIDCompleted += new EventHandler<getResultsByIDCompletedEventArgs>(client_getResultsByIDCompleted);
            client.getResultsByIDAsync(Convert.ToInt32(textBox1.Text));

        }

this does not seem to work.


any help would be much appreciated.
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Perhaps these examples/articles can help you further

Passing Values between forms in Silverlight
http://www.c-sharpcorner.com/UploadFile/prvn_131971/PassingValuesSilverlight11192008060441AM/PassingValuesSilverlight.aspx

Silverlight How To Pass Values Between Pages or Forms
http://www.xploredotnet.com/2009/12/silverlight-how-to-pass-values-between.html
ASKER CERTIFIED SOLUTION
Avatar of tovvenki
tovvenki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of baz86
baz86

ASKER

Hi Dhaest and tovvenkit,
Thank you both for your replies.
@Dhaest. The links were useful but as i'm a beginner in all this i'm not sure how i could work that with the list box in form 1.
@tovvenkit. Yes still having issues unfortunately. Would you please be able to expand on the code in both forms to what i should be looking to get because im having no luck. I can't seem to access the ID of the selected item and pass that on.
Avatar of baz86

ASKER

This is the xaml for the first page and it shows how the structure of the list box for your information
<ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock x:Name="txtSiteID" Text="{Binding site_id}" Margin="5" Foreground="Red"/>
                                        <TextBlock Text="{Binding site_name}" Margin="5" Style="{StaticResource TitleBlock}"/>
                                        <TextBlock Text="{Binding site_postcode}" Margin="5" Style="{StaticResource TitleBlock}"/>
                                    </StackPanel>

                                </DataTemplate>
                            </ListBox.ItemTemplate>

Open in new window

Avatar of baz86

ASKER

On page1 i can set the .ItemSource for page2 as whatever is selected in the list box on page one. But I can't seem to pass say the USERID from the listbox into a query in page 2 each time i call a new instance of page 2....any ideas?
It sounds like you are trying to do master/detail linking.  This article walks you through it.
http://www.silverlight.net/learn/videos/all/simple-masterdetails-with-datagrid/
Avatar of baz86

ASKER

Hi tovvenki,
Your suggestion of passing the value in the constructor worked like a charm! Thanks!!
Avatar of baz86

ASKER

suggestion of passing the value in the constructor worked like a charm! Thanks!!