![](/img/trans.png)
[英]Xamarin.Forms DatePickerCustomRenderer doesn't recognize the IOnDateSetListener
[英]Xamarin Forms - Recognize Postition
我想發表一條僅當用戶在文章底部時才可見的評論條目。 因此,應用程序必須識別用戶何時滾動足夠,然后一種方法應使輸入字段可見。
我在互聯網上找不到這樣的東西,所以也許你們可以幫我。
如果使用的是ScollView
,則在滾動視圖時將觸發Scrolled
事件,並且ScrolledEventArgs
包含ScrollX
和ScrollY
屬性,這些屬性使您可以了解ScrollView
當前所在的位置。 如果將ScrollY
與ScrollView
的ContentSize
屬性的高度進行比較,例如:
XAML:
<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
子類):
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;
}
也就是說,為什么不使用相同的滾動視圖將條目放在文章下方? IOW只是將Entry
元素放在同一StackLayout
上方Label
之后,Entry始終始終位於末尾,但是用戶只有向下滾動才能看到它。 似乎這將是一個更簡單的解決方案。 當然,您可能沒有使用Label
但同樣適用,只是將Entry
放在ScrollView
滾動的布局的底部。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.