How can a Storyboard triggered on a ControlTemplate be targeted to a generated child of the ControlTemplate?
Setting the Storyboard.TargetName
doesn't work here. It throws 'targetButton' name cannot be found in the name scope of 'System.Windows.Controls.ControlTemplate'
.
Is there another way to accomplish this?
<ControlTemplate x:Key="aTemplate"
TargetType="someType">
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="targetButton ???"
Storyboard.TargetProperty="Opacity"
From="0" To="1" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</ControlTemplate.Triggers>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel>
<Label Content="..." />
开发者_开发知识库 <Button Opacity="0"
x:Name="targetButton" />
</StackPanel>
<ContentPresenter Grid.Row="1" />
</Grid>
</ControlTemplate>
精彩评论