Access fields from another tab in wpf

Partha Mandayam 91 Reputation points
2022-10-18T11:47:36.903+00:00

I have a tab control and when a button on tab1 is clicked I need to update a grid on tab3 with some field values from tab1
How to do this?

Developer technologies | Windows Presentation Foundation
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2022-10-19T02:21:36.13+00:00

    Hi,@Partha Mandayam . Welcome Microsoft Q&A.
    If your field is assignment, you could refer to the code below.

    MainWindow.xaml:

    <Grid>  
            <TabControl >  
                <TabItem Header="Tab1">  
                    <Grid Background="AliceBlue">  
                        <Button x:Name="btn" Width="100" Height="50" Click="btn_Click"  Content="tab1"/>  
                    </Grid>  
                </TabItem>  
                 
                <TabItem Header="Tab3">  
                    <Grid Background="#FFE5E5E5">  
                        <Grid.ColumnDefinitions>  
                            <ColumnDefinition Width="67"/>  
                            <ColumnDefinition Width="330*"/>  
                        </Grid.ColumnDefinitions>  
                        <TextBox x:Name="tb1" Text="hello" Width="200" Background="AliceBlue" Height="50"  />  
                        <TextBox x:Name="tb2" Grid.Column="1" Text="hi" Width="200" Background="AliceBlue" Height="50"/>  
                    </Grid>  
                </TabItem>  
            </TabControl>  
      
        </Grid>  
    

    MainWindow.xaml.cs:

    private void btn_Click(object sender, RoutedEventArgs e)  
            {  
                tb2.Text = "ok";  
            }  
    

    ----------------------------------------------------------------------------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.