确定LongListSelector何时滚动

时间:2014-09-18 01:50:03

标签: c# windows-phone-8 converter longlistselector

我只是希望能够在向下滚动时最小化应用程序栏,然后在向上滚动时显示其正常大小。我在facebook应用程序上看到了这种能力,它看起来非常吸引人且用户友好。我有我的LongListSelector与绑定它的项目,以及已经在代码后面的appbar。启用此功能的缺失键是什么?

2 个答案:

答案 0 :(得分:0)

您只需要确定用户何时滚动以及向何方向滚动。这是一篇包含示例代码的精彩文章。 Detecting WP8 LongListSelector’s end of scroll。您可以将其修改为完全符合您要求的位置。

然而,如果我要去做,我会采取更直接的方式。我会派生自己的LLS并将属性附加到滚动条的值。像这样:)

public class MyLLS : LongListSelector, INotifyPropertyChanged
{
    // implement the INotify
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {            
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        // dat grab doe
        sb = this.GetTemplateChild("VerticalScrollBar") as System.Windows.Controls.Primitives.ScrollBar;
        sb.ValueChanged += sb_ValueChanged;           
    }

    void sb_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
    {
        // an animation has happen and they have moved a significance distance
        // set the new value
        ScrollValue = e.NewValue;

        // determine scroll direction
        if(e.NewValue > e.OldValue)
        {
            scroll_direction_down = true;
        }
        else
        {
            scroll_direction_down = false;
        }
    }

    public System.Windows.Controls.Primitives.ScrollBar sb;

    private bool scroll_direction_down = false;   // or whatever default you want

    public bool ScrollDirectionDown
    { get { return scroll_direction_down; } }

    public double ScrollValue
    {
        get
        {
            if (sb != null)
            {
                return sb.Value;
            }
            else
                return 0;
        }
        set
        {
            sb.Value = value;
            NotifyPropertyChanged("ScrollValue");
        }
    }
}

现在你知道了确切的滚动位置。您甚至可以通过

获得最高和最低价值
double min = this.sb.Minimum;
double max = this.sb.Maximum;

现在将ScrollDirectionDown属性绑定到转换器,使其符合您的AppBar,您就可以实现目标。


如果您无法绑定,则必须进行回调以更新可见性。但是如果你想要更简单的东西,只需将它连接到自定义LLS的ManipulationStateChanged事件。

public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
    } 

    private void lls_ManipulationStateChanged(object sender, EventArgs e)
    {
        if (lls.ScrollDirectionDown)
        {
            ApplicationBar.IsVisible = false;
        }
        else
        {
            ApplicationBar.IsVisible = true;
        }             
    }
}

答案 1 :(得分:0)

因此,您必须检测longlistselector何时开始滚动。为了达到这个目的,这里有一个类似的主题:

Windows Phone 8 Long List Selector - scroll to bottom after data loaded async

DoAndScroll方法中,您只需添加代码即可最小化AppBar

在您的appbar的xaml代码中,将模式更改为Minimized。

<shell:ApplicationBar Mode="Minimized" Opacity="1.0" IsMenuEnabled="True" IsVisible="True"></>

此后,无论何时向上滚动,请将Mode的{​​{1}}设为AppBar

或者看看这个以检测Default的底部。

Detecting WP8 LongListSelector’s end of scroll