2
<Canvas>
    <Button Name="b1" Content="Button"/>
    <Rectangle Name="Mr1" Fill="Black">
        <Rectangle.Triggers>
            <EventTrigger SourceName="b1" RoutedEvent="Button.Click">
                <BeginStoryboard>
                 <code.../>
                </BeginStoryboard>
            </EventTrigger>
        </Rectangle.Triggers>
    </Rectangle>
</Canvas>

错误:找不到b1。

请帮帮我,谢谢。

4

2 回答 2

5

我只是面临同样的问题..为其他感兴趣的人发布解决方案。

<Canvas>

    <Canvas.Resources>
        <Storyboard x:Key="MyAwesomeAnimation" Storyboard.TargetName="Mr1" Storyboard.TargetProperty="Height">
            <!-- Some Awesome animation here..-->
        </Storyboard>
    </Canvas.Resources>

    <Button Name="b1" Content="Button">
        <Button.Triggers>
            <!--The key is to define the click trigger on the button. Why should the rectangle know about the button?-->
            <EventTrigger RoutedEvent="Button.Click">
                <BeginStoryboard Storyboard="{StaticResource MyAwesomeAnimation}"></BeginStoryboard>
            </EventTrigger>
        </Button.Triggers>
    </Button>

    <Rectangle Name="Mr1" Fill="Black" />

</Canvas>
于 2017-03-01T00:52:46.743 回答
1

您可以将此属性设置为应用触发器集合(此触发器所属的集合)范围内的任何元素的名称。这通常是包含此 Trigger 的模板中的命名元素。

于 2012-04-09T00:17:07.120 回答