如何从代码后面操纵扩展器头

时间:2014-07-01 18:54:58

标签: c# wpf xaml controls expander

我在XAML中有这段代码:

  <Expander BorderBrush="DarkGray" Background="White" SourceUpdated="Expander_SourceUpdated" GotFocus="Expander_GotFocus">
                                                <Expander.Header>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="Grupo " VerticalAlignment ="Center"/>
                                                        <TextBlock x:Name="Tblockgrupo" Text="{Binding Name}" VerticalAlignment ="Center" GotFocus="TextBlock_GotFocus" />
                                                        <TextBlock Text="{Binding ItemCount}" VerticalAlignment ="Center"/>
                                                        <TextBlock Text=" Variable(s)" VerticalAlignment ="Center"/>
                                                    </StackPanel>
                                                </Expander.Header>
                                                <ItemsPresenter />
                                            </Expander>

我的问题是如何在扩展器具有焦点时从代码隐藏(c#)捕获具有名称的文本块文本:Tblockgroup。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案

object result = Prueba.FindName(&#34; name&#34;);             if(结果是TextBlock)             {                 //如果找到Text元素,则执行以下内容。                 TextBlock resultconvert =结果为TextBlock;                 MessageBox.Show(resultconvert.Text);             }