How does WPF access controls in inline templates?

Hanying Li 1 Reputation point

for example:
<ToggleButton x:Name="FlipButton">
<Grid Margin="0,5,0,0">
<Path Data="M0,0 L8,8 0,16" Stroke="White">
<RotateTransform x:Name="Tag"/>
I want to animate the "Tag" object in the inline template at some point, but when I apply the animation, I will be prompted that the name cannot be found. Is there any way to deal with this problem?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,635 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DaisyTian-1203 11,611 Reputation points

    You can use below code to get RotateTransform named Tag .

     RotateTransform tag = (RotateTransform)FlipButton.Template.FindName("Tag", FlipButton);  

    There is a Microsoft document How to: Find ControlTemplate-Generated Elements giving a detailed description of it. By the way, if I misunderstand your question, please point out.

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments