Вы можете использовать ItemAppearing
событие. При переходе к последнему элементу отображается кнопка «вверх». И когда вы прокручиваете первый элемент, скрываете эту кнопку.
ItemAppearing
: https://docs.microsoft.com/en-us/dotnet/api/Xamarin.Forms.ListView.ItemAppearing?view=xamarin-forms
Xaml:
<StackLayout>
<ListView
ItemAppearing="ListView_ItemAppearing"
ItemsSource="{Binding strs}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Str}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ImageButton
x:Name="btn_Icon"
HorizontalOptions="End"
IsVisible="False"
Source="up_big.png" />
</StackLayout>
Код:
public partial class Page7 : ContentPage
{
public ObservableCollection<Strs> strs { get; set; }
public Page7()
{
InitializeComponent();
strs = new ObservableCollection<Strs>()
{
new Strs(){ Str="mono1"},
new Strs(){ Str="mono2"},
new Strs(){ Str="mono3"},
new Strs(){ Str="mono4"},
new Strs(){ Str="mono5"},
new Strs(){ Str="mono6"},
new Strs(){ Str="mono7"},
new Strs(){ Str="mono8"},
new Strs(){ Str="mono9"},
new Strs(){ Str="mono10"},
new Strs(){ Str="mono11"},
new Strs(){ Str="mono12"},
new Strs(){ Str="mono13"},
new Strs(){ Str="mono14"},
new Strs(){ Str="mono15"},
new Strs(){ Str="mono16"},
new Strs(){ Str="mono17"},
new Strs(){ Str="mono18"},
new Strs(){ Str="mono19"},
new Strs(){ Str="mono20"},
new Strs(){ Str="mono21"},
new Strs(){ Str="mono22"},
new Strs(){ Str="mono23"}
};
this.BindingContext = this;
}
private void ListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
{
var item = e.Item as Strs;
if (item == strs.Last())
{
btn_Icon.IsVisible = true;
}
else if (item == strs.First())
{
btn_Icon.IsVisible = false;
}
}
}
public class Strs
{
public string Str { get; set; }
}