我想得到一个图形元素的内容出现在一个WPF的TabItem。
考虑窗口的以下代码:
<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>我已经查找了TabItem documentation on MSDN,但没有找到任何有用的信息。
有没有办法从TabItem中获取"txtContent“文本框中的内容?
发布于 2017-08-09 18:31:03
试试这个:
Grid grid = TheItem.Content as Grid;
TextBox txtContent = grid.Children[0] as TextBox;
string text = txtContent.Text;或者简单地说:
TextBox txtContent = MainGrid.Children[0] as TextBox;https://stackoverflow.com/questions/45587983
复制相似问题