1

如果用户将媒体文件滚动到视图中,我需要自动播放它。

我得到了这样的东西:

<ScrollViewer>
   <ItemsControl ItemsSource="{Binding SelectedProduct.Entities}" ItemTemplateSelector="{StaticResource EntityDataTemplateSelector}" />             
</ScrollViewer>

在其中一个 DataTemplates 中,我使用的是 PlayerFramework 的媒体播放器(Codeplex 上的 PlayerFramework )。

当用户将媒体播放器(手动)滚动到视图中时。视频将开始播放。

我的问题是:如何确定元素是否在视口中?

我很早就写了这篇文章,但它不适用于winrt。

希望你能帮助我。提前致谢!

朱利安

4

1 回答 1

3

我可以通过将这篇文章中的方法调整为:

private bool IsVisibileToUser ( FrameworkElement element, FrameworkElement container )
    {
        if ( element == null || container == null )
            return false;

        if ( element.Visibility != Visibility.Visible )
            return false;

        Rect elementBounds = element.TransformToVisual( container ).TransformBounds( new Rect( 0.0, 0.0, element.ActualWidth, element.ActualHeight ) );
        Rect containerBounds = new Rect( 0.0, 0.0, container.ActualWidth, container.ActualHeight );

        return (elementBounds.Top < containerBounds.Bottom && elementBounds.Bottom > containerBounds.Top);
    }

这仅适用于垂直滚动。如果需要水平滚动,则需要在方法末尾修改返回值。

最好的问候朱利安

于 2013-07-16T14:56:04.843 回答