【问题标题】:ScrollViewer reaching bottom WindowsPhone8ScrollViewer 到达底部 WindowsPhone8
【发布时间】:2013-09-12 21:51:38
【问题描述】:

当用户到达 (ScrollViewer)Page 的末尾时,我正在尝试打开 App-Bar... 因此,当到达终点时,我需要一个指示器...

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

       <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 来关闭和打开它。现在它工作正常(顺利):

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

【问题讨论】:

  • 也许编写自己的代码会有所帮助,因为不存在此类事件
  • 这个问题是询问事件而不是检查偏移量的方式,我在问题中写道,副本是“过度杀伤”。..

标签: xaml windows-phone-8 winrt-xaml scrollviewer appbar


【解决方案1】:

使用更新的布局这里是我使用和调试以获得滚动效果的代码。您可能还需要跟踪指针被按下的位置以及滚动查看器操作完成事件。这是在 xaml 后面的代码中添加相应的事件处理程序。

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

如果成功了请告诉我

【讨论】:

  • 我编辑了我的问题。 layoutUpdated 事件非常适合这一点。我没有“ponterPressed”事件......但无论如何都可以使用,只需使用“layoutUpdated”。我不知道其他事件有什么目的。谢谢!
  • 欢迎您 :) 请告诉我是否还有其他问题 :) 显然在我的范围内 :D
猜你喜欢
  • 2012-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-20
  • 2012-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多