这是xml:
<Page.Resources>
<ControlTemplate x:Key="WeddingButtonBigTemplate" TargetType="Button">
<Grid>
<Image x:Name="imgNormal" Source="../Images/Married_button2.png"/>
<TextBlock x:Name="textBlock2" Style="{StaticResource RegularBlueSpecialBoldText}" LineHeight="28" LineStackingStrategy="BlockLineHeight" HorizontalAlignment="Center" Margin="10,30,10,70" TextWrapping="Wrap" TextAlignment="Center" VerticalAlignment="Stretch" >
<Run FontSize="20" Text="The event of"></Run>
<Run FontSize="28" Text="{DynamicResource strBride}"></Run>
</TextBlock>
</Grid>
</ControlTemplate>
</Page.Resources>
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Width="1000">
<Button x:Name="btnWedding" HorizontalAlignment="Left" Margin="10,20,0,-49" VerticalAlignment="Top" Template="{StaticResource WeddingButtonBigTemplate}" Foreground="#FF2B4072" Width="380" Click="btnClick" />
</Grid>
我正在尝试访问名为textBlock2
.
我试图覆盖OnApplyTemplate
但为空。
我试过了:
Grid gridInTemplate = (Grid)btnWedding.Template.FindName("grid", btnWedding);
var ct0 = btnWedding.Template.FindName("textBlock2", btnWedding);
var ct1 = btnWedding.FindName("textBlock2");
var ct2 = btnWedding.FindResource("textBlock2");
gridInTemplate 为空(取自 MSDN 的示例)。
当然,ct# 都是空的。
我在这里想念什么?