question

HanyingLi-9795 avatar image
0 Votes"
HanyingLi-9795 asked DaisyTian-1203 answered

How does WPF access controls in inline templates?

for example:
<ToggleButton x:Name="FlipButton">
<ToggleButton.Template>
<ControlTemplate>
<Grid Margin="0,5,0,0">
<Path Data="M0,0 L8,8 0,16" Stroke="White">
<Path.RenderTransform>
<RotateTransform x:Name="Tag"/>
</Path.RenderTransform>
</Path>
</Grid>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
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-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DaisyTian-1203 avatar image
0 Votes"
DaisyTian-1203 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.