繁体   English   中英

WinRT - 确定元素是否对用户可见

[英]WinRT - determine if an element is visible to the user

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

我有这样的事情:

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

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

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

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

我很早就去了这篇文章,但它没有在winrt上工作。

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

朱利安

我可以通过调整此帖子中的方法来解决问题:

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);
    }

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

最好的问候朱利安

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM