简体   繁体   English

如何从背后的代码操纵扩展头

[英]How manipulate expander header from code behind

I have this code in XAML: 我在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>

My question is how capture the text of the TextBlock with name: Tblockgroup, from codebehind (c#) when the expander has focus. 我的问题是,当扩展器具有焦点时,如何从代码隐藏(c#)中捕获名称为Tblockgroup的TextBlock文本。

I found the solution 我找到了解决方案

object result = Prueba.FindName("name"); 对象结果= Prueba.FindName(“ name”); if (result is TextBlock) { // Following executed if Text element was found. if(结果是TextBlock){//如果找到Text元素,则执行以下操作。 TextBlock resultconvert = result as TextBlock; TextBlock resultconvert =结果为TextBlock; MessageBox.Show(resultconvert.Text); MessageBox.Show(resultconvert.Text); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM