我要发表一条仅当用户在文章底部时才可见的评论条目。 因此,应用必须识别用户何时滚动足够的时间,然后一种方法应使输入字段可见。
我在互联网上找不到这样的东西,所以也许你们可以帮助我。
This one is without the entryfield and when the user scrolls down ...
答案 0 :(得分:0)
如果您使用的是ScollView
,则将在滚动视图并且Scrolled
包含ScrolledEventArgs
和ScrollX
属性时触发一个ScrollY
事件让您知道ScrollView
当前所在的位置。如果您将ScrollY
与ContentSize
的{{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
正在滚动的布局的底部即可。