Xamarin表格-识别职位

时间:2018-12-03 19:13:34

标签: c# forms xamarin position visible

我要发表一条仅当用户在文章底部时才可见的评论条目。 因此,应用必须识别用户何时滚动足够的时间,然后一种方法应使输入字段可见。

我在互联网上找不到这样的东西,所以也许你们可以帮助我。

This one is without the entryfield and when the user scrolls down ...

... the entryfield becomes visible

1 个答案:

答案 0 :(得分:0)

如果您使用的是ScollView,则将在滚动视图并且Scrolled包含ScrolledEventArgsScrollX属性时触发一个ScrollY事件让您知道ScrollView当前所在的位置。如果您将ScrollYContentSize的{​​{1}}属性的高度进行比较,例如:

XAML:

ScrollView

后面的代码(<StackLayout> <ScrollView x:Name="scrollView" Scrolled="Handle_Scrolled"> <StackLayout> <Label Text="{Binding Article}" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand" /> </StackLayout> </ScrollView> <Entry IsVisible="{Binding AtEnd}" Placeholder="End reached!" /> </StackLayout> MainPage的子类):

ContentPage

也就是说,为什么不使用相同的滚动视图将条目放在文章下方? IOW只是将string _article; public string Article { get { return _article; } set { if (_article != value) { _article = value; OnPropertyChanged("Article"); } } } bool atEnd; public bool AtEnd { get { return atEnd; } set { if (atEnd != value) { atEnd = value; OnPropertyChanged("AtEnd"); } } } public MainPage() { Article = "<put in enough text here to force scrolling>"; AtEnd = false; InitializeComponent(); BindingContext = this; } void Handle_Scrolled(object sender, Xamarin.Forms.ScrolledEventArgs e) { if (e.ScrollY + scrollView.Height >= scrollView.ContentSize.Height) AtEnd = true; else AtEnd = false; } 元素放在上述Entry的上方Label之后,并且Entry始终总是位于结尾处,但是用户只有向下滚动才能看到它。似乎这将是一个更简单的解决方案。当然,您可能未使用StackLayout,但同样适用,只需将Label放在Entry正在滚动的布局的底部即可。