开发者

How can a Storyboard triggered on a ControlTemplate be targeted to a generated child of the ControlTemplate?

开发者 https://www.devze.com 2023-03-21 06:31 出处:网络
Setting the Storyboard.TargetName doesn\'t work here.It throws \'targetButton\' name cannot be found in the name scope of \'System.Windows.Controls.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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号