Dastardly
Dastardly

Reputation: 19

Explore a WPF TabItem

I want to get the content of a graphical elements present in a WPF TabItem.

Consider the following code for the window :

<TabItem x:Name="TheItem" Header="Form">
    <Grid x:Name="MainGrid">
        <TextBox x:Name="txtContent" Text="Hello I'm some content !" />
        <TextBox x:Name="txtOther" Text="Some other content" />
    </Grid>
</TabItem>

I've looked up the TabItem documentation on MSDN but failed to find any useful information.

Is there any way to get the content from the "txtContent" textbox from a TabItem ?

Upvotes: 0

Views: 53

Answers (1)

mm8
mm8

Reputation: 169350

Try this:

Grid grid = TheItem.Content as Grid;
TextBox txtContent = grid.Children[0] as TextBox;
string text = txtContent.Text;

Or simply:

TextBox txtContent = MainGrid.Children[0] as TextBox;

Upvotes: 2

Related Questions