从Parent Control访问UserControl中的Control.Property

时间:2014-07-04 12:03:16

标签: c# wpf xaml

我试图让Ellipse闪烁以防另一个UserControl内的图标为暂停,如果图标为播放则停止闪烁。

以下是Ellipse以及我尝试使用PlayIcon.Opacity绑定到DataTrigger,但无效

<Ellipse.Style>
    <Style TargetType="{x:Type Ellipse}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Opacity, Path=PlayIcon, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type views:PlayButton}}}" Value="0">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation 
                                 Storyboard.TargetProperty="Opacity"
                                 From="0"
                                 To="3"
                                 RepeatBehavior="Forever"
                                 AutoReverse="True"
                                 Duration="0:0:0.1"/>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Ellipse.Style>

<views:PlayButton />

以下是PlayButton UserControl

中的暂停和播放图标
<UserControl x:Class="MyNamespace.PlayButton" ...>
    ...
    <Path Name="PlayIcon" Fill="Blue" Opacity="0" Data="M18,12 18,38 35,25"/>
    <Path Name="PauseIcon" Fill="Blue" Opacity="10"  Data="M15,12 15,38 23,38 23,12z M27,12 27,38 35,38 35,12" />
    ...
</UserControl>

如果Play图标的不透明度为0,或者PlayButton UserControl中的Pause图标Opacity为10,我该如何触发此DataTrigger?

0 个答案:

没有答案