This project has moved. For the latest updates, please go here.

ChildWindow - How to pass a value from a childwindow to a main form

Jan 7, 2014 at 2:24 PM
Hi,
I do have a simple form where a user enters a value in a childwinow modal then when the childwindow modal is closed, I want to get the value entered by the user and populate it in the main form.
        <Grid Grid.Row="1">               
            <TextBox x:Name="txtResult" 
                          Text="" BorderThickness="1" BorderBrush="Black" 
                          Height="20" Margin="10"/>
        </Grid>

        <Border Grid.Row="1">
            <xctk:WindowContainer Background="Transparent" 
                                    ModalBackgroundBrush="#80000000">
                <xctk:ChildWindow x:Name="_childWindow"
                                  WindowBackground="#9A9999"
                                  Caption="Modal ChildWindow"
                                  IsModal="True"
                                  Left="75"
                                  Top="50"
                                  Width="275"
                                  Height="125"
                                  WindowState="Open">
                    <TextBox x:Name="txtUserInput" 
                                   Text="" 
                                   BorderThickness="1" 
                                   BorderBrush="Black" 
                                   Height="20" Margin="10"/>
                </xctk:ChildWindow>
            </xctk:WindowContainer>
        </Border>
Based on above codes, I want to get a value from txtUserInput and populate it in txtResult. Please advise.

Thanks,
Brew
Developer
Jan 7, 2014 at 5:16 PM
Hi,

You can use a binding to update the Text value :
 <TextBox x:Name="txtResult"
                  Text="{Binding Text, ElementName=txtUserInput}"
                  BorderThickness="1"
                  BorderBrush="Black"
                  Height="20"
                  Margin="10" />
Or you can use the Closed event from ChildWindow to update the text :
 <xctk:ChildWindow x:Name="_childWindow"
                              WindowBackground="#9A9999"
                              Caption="Modal ChildWindow"
                              IsModal="True"
                              Left="75"
                              Top="50"
                              Width="275"
                              Height="125"
                              WindowState="Open"
                              Closed="_childWindow_Closed_1">
               <TextBox x:Name="txtUserInput"
                        Text=""
                        BorderThickness="1"
                        BorderBrush="Black"
                        Height="20"
                        Margin="10" />
            </xctk:ChildWindow>


private void _childWindow_Closed_1( object sender, EventArgs e )
    {
      txtResult.Text = txtUserInput.Text;
    }
Jan 8, 2014 at 4:28 PM
Thank you. It really simple than I thought!