滚动listview时隐藏和显示calandar可见性-xamarin.forms
我有一个xamarin.forms应用程序,上面有一个日历视图,下面有一个列表视图 我试图实现的是,当日历视图下的listview向下滚动时,日历应隐藏,以便listview占据整个屏幕。当listview向上滚动时,日历应重新显示为以前的状态。xamarin、forms是否可能实现这一点 我的xaml滚动listview时隐藏和显示calandar可见性-xamarin.forms,listview,xamarin.forms,Listview,Xamarin.forms,我有一个xamarin.forms应用程序,上面有一个日历视图,下面有一个列表视图 我试图实现的是,当日历视图下的listview向下滚动时,日历应隐藏,以便listview占据整个屏幕。当listview向上滚动时,日历应重新显示为以前的状态。xamarin、forms是否可能实现这一点 我的xaml <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="0.8*"/>
<RowDefinition Height="0.25*"/>
</Grid.RowDefinitions>
<Calendar x:Name="Calendar"
Grid.Row="0">
</Calendar>
<ListView x:Name="listView"
ItemAppearing="Handle_ItemAppearing"
Grid.Row="1">
<ListView.ItemTemplate>
...
</ListView.ItemTemplate>
</ListView>
<StackLayout x:Name="stackLayout"
Grid.Row="2">
<Button></Button>
<Button></Button>
</StackLayout>
</Grid>
...
我的xaml.cs文件和我尝试的内容
public partial class MainPage : ContentPage
{
public ObservableCollection<string> Items { get; set; } = new ObservableCollection<string>();
int lastItemIndex;
int currentItemIndex;
public MainPage()
{
...
}
void Handle_ItemAppearing(object sender, ItemVisibilityEventArgs e)
{
string item = e.Item as string;
currentItemIndex = Items.IndexOf(item);
if (currentItemIndex > lastItemIndex)
{
Calendar.IsVisible = false;
}
else
{
Calendar.IsVisible = true;
}
lastItemIndex = currentItemIndex;
}
}
public分部类主页面:ContentPage
{
公共ObservableCollection项{get;set;}=new ObservableCollection();
int-lastItemIndex;
int-currentItemIndex;
公共主页()
{
...
}
无效句柄\u项出现(对象发送方,项可见性事件参数e)
{
string item=e.作为字符串的项;
currentItemIndex=Items.IndexOf(item);
如果(currentItemIndex>lastItemIndex)
{
Calendar.IsVisible=false;
}
其他的
{
Calendar.IsVisible=true;
}
lastItemIndex=currentItemIndex;
}
}
不知怎么的,它不起作用。非常感谢您的帮助。请提前感谢。您可以尝试将日历放到listView的列表中
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="450"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListView x:Name="listView"
Grid.Row="0">
<!--put the listview here-->
<ListView.Header>
<Calendar x:Name="Calendar" >
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout x:Name="stackLayout"
Grid.Row="1">
<Button></Button>
<Button></Button>
</StackLayout>
</Grid>
...
检查它是否符合您的要求。我会尝试分别测试这两种功能。你能在你期望的时候(在你的listview中向下滚动)点击Handle_Item中出现的断点吗?你能手动隐藏你的日历吗?例如,通过设置一个计时器,将IsVisible设置为false?@Mouse On Mars bro我可以手动隐藏日历视图。但它会在日历的整个空间留下一个白色屏幕。listview仍在其位置,而不占用整个屏幕area@AndroDevil我可以知道你用哪种日历吗?@PrissyEve嗨,我使用了syncfusion calandersyncfusion是一个付费日历或免费日历,但我得到了一个错误系统。ArgumentOutOfRangeException:索引超出范围。必须为非负数且小于集合的大小。参数名称:IndexyYou应该检查listView的itemSource。