I want to get an element (path) that is the template of my content control. I want to get a link to "contour_forme", but every solution found on the Internet returns null. I tried to override OnApplyTemplate, but still null:
public override void OnApplyTemplate() { base.OnApplyTemplate(); var template = this.pion_test.Template; var contour = GetTemplateChild("contour_forme"); forme_path = template.FindName("contour_forme", this.pion_test) as Path; Path path = FindVisualChild<Path>(this.pion_test); var test = this.pion_test.FindName("contour_forme"); var test2 = this.pion_test.Template.FindName("contour_forme", this.pion_test); }
my xaml:
<UserControl.Resources> <Style TargetType="{x:Type ContentControl}" x:Key="StylePion"> <Setter Property="BorderBrush" Value="Black"/> <Setter Property="Background" Value="White" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ContentControl"> <Grid Width="33" Height="34"> <Path x:Name="contour_forme" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" Stretch="Uniform" Width="28" HorizontalAlignment="Left" Margin="0,-1,0,0" RenderTransformOrigin="0.59,0.5" Fill="{TemplateBinding Background}" Data="M17.36,24.623c-2.142-0.006-4.153-0.552-5.907-1.506l0,0l-0.076-0.046 c-1.952-1.08-3.57-2.673-4.692-4.589L0,11.942l7.126-6.514c1.077-1.584,2.519-2.896,4.2-3.84l0.127-0.077l0,0 C13.23,0.544,15.27-0.006,17.441,0c6.844z" Tag="{TemplateBinding Tag}" > <Path.RenderTransform> <RotateTransform Angle="50"/> </Path.RenderTransform> </Path> <Ellipse Width="21" Height="21" VerticalAlignment="Center" HorizontalAlignment="Center" Fill="{TemplateBinding Background}" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources> <Grid Name="grid_pion"> <ContentControl Name="pion_test" HorizontalAlignment="Center" VerticalAlignment="Center" Tag="4" Content="5" Style="{StaticResource StylePion}" > </ContentControl> </Grid>
I want to find a link to install rotary conversion on it.
What am I doing wrong?
source share