本文介绍了ScrollViewer 到达底部 WindowsPhone8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户到达(ScrollViewer)页面的末尾时,我试图打开一个应用程序栏......因此我需要一个到达终点时的指示器...

Im trying to open a App-Bar when the user reaches the end of the (ScrollViewer)Page...Therefore I need a indicator when the end is reached...

  • My Scrollviewer (maybe because WP8) has no "ViewChanged"-eventlike posted in other questions
  • And this solution is just overkill for my Problem I think:http://blogs.msdn.com/b/slmperf/archive/2011/06/30/windows-phone-mango-change-listbox-how-to-detect-compression-end-of-scroll-states.aspx

我在此查看器中找不到任何可以帮助我的事件...

I cant find any event within this Viewer which could help me...

       <ScrollViewer x:Name="SV_ScrollViewer"
                      Grid.Row="1"
                      Margin="12,0,12,0"
                      ManipulationMode="Control"
                      AllowDrop="False">
            <Grid x:Name="ContentPanel">
                <StackPanel>
                    <Controls:Map
                        Height="730"
                        x:Name="M_MainMap"
                        ZoomLevel="10"
                        Loaded="Map_Loaded"/>
                    <phone:LongListSelector
                        x:Name="LLS_FuelStations"
                        Height="700">
                    </phone:LongListSelector>
                </StackPanel>
            </Grid>
        </ScrollViewer>

感谢您的帮助!

2-LayoutUpdated-Event 不适合再次关闭应用栏......我最终使用了一个 Dispatcher-Timer 来关闭和打开它.现在它工作正常(流畅):

2- The LayoutUpdated-Event was not good for closing app-bar again... I ended up with a Dispatcher-Timer for closing AND opening it. Now it works fine (smooth):

    // Constructor
    public MainPage()
    {
        InitializeComponent();

        Dispatcher.BeginInvoke(() =>
        {
            //initialize timer
            if (timer == null)
            {
                int timerSpan = 500;
                timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(timerSpan) };
                timer.Tick += (o, arg) => OffsetWatcher();
            }
        });
    }

关闭和打开应用栏:

private void OffsetWatcher()
        {
            if (SV_ScrollViewer.ScrollableHeight - SV_ScrollViewer.VerticalOffset > 100 )
            {
                if (ApplicationBar.IsVisible)
                {
                    ApplicationBar.IsVisible = false;
                    ApplicationBar.IsMenuEnabled = false;
                }
            }
            else
            {
                if (!ApplicationBar.IsVisible)
                {
                    BuildLocalizedApplicationBar();
                }
            }
        }

推荐答案

Use Layout Updated 下面是我使用和调试以获得滚动效果的代码.您可能还需要跟踪指针被按下的位置和滚动查看器操作完成事件.这里的xaml在后面的代码中添加了各自的事件处理程序.

Use Layout Updated Here's code I used and debugged to get the scrolling effect. You might also need to keep a track where the pointer has been pressed and the scroll viewer manipulation completed event. Here's the xaml Add the respective event handler in the code behind.

 <ScrollViewer ManipulationCompleted="ScrollViewer_ManipulationCompleted" ManipulationMode="All">
        <StackPanel  LayoutUpdated="StackPanel_LayoutUpdated" PointerPressed="StackPanel_PointerPressed">
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
            <Grid Height="100" Width="100" Background="Red" ></Grid>
            <Grid Height="100" Width="100" Background="Green" ></Grid>
            <Grid Height="100" Width="100" Background="Blue" ></Grid>
            <Grid Height="100" Width="100" Background="Yellow" ></Grid>
        </StackPanel>
    </ScrollViewer>

这是后面的代码

        public MainPage()
    {
        this.InitializeComponent();
    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {

    }


    private void ScrollViewer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        //scroll bar being dragged
    }

    private void StackPanel_LayoutUpdated(object sender, object e)
    {
        //if swipe gesture then check for vertical offset and carry on with the //calculations you have to do else do nothing
    }

    private void StackPanel_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
        //swipe gesture being made
    }

请告诉我它是否有效

这篇关于ScrollViewer 到达底部 WindowsPhone8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:13