如何在 Xamarin Forms 中的其他项目之上(之上)显示 ListView?

朱尼德·汗·莫明

我有一个ListView显示最近的搜索项目。我已将其添加到主页的堆栈布局中。我想像这样显示ListView其他 UI 元素:在此处输入图片说明如何完成。

我目前正在为SearchBar使用一个新页面ListView在主页上我只有一个搜索按钮,当我单击该按钮时,应用程序导航到包含SearchBar的新页面ListView但我希望它在同一页面上完成。当搜索按钮被点击,SearchBarListView表现出比其他UI元素变得可见。

这是我的代码:

在 MainPage.xaml 上

<Button Text="Search" Clicked="SearchButtonPressed" />

C#代码

void SearchButtonPressed(object sender, EventArgs e)
{
    Navigation.PushAsync(new SearchPage());
}

SearchPage.xaml 代码

<StackLayout>
    <SearchBar x:Name="SearchBar"
                TextChanged="Handle_SearchButtonPressed"
                Placeholder="Search places..."
                CancelButtonColor="Red" />

    <ListView x:Name="ListView" ItemsSource="{Binding Source=list}" RowHeight="50" IsVisible="True">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell Tapped="ViewCell_Tapped">
                    <Label Text="{Binding}" TextColor="Black" VerticalOptions="Center" />
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>
内尔-IT

你可以用网格来做:

<Grid>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>


    <Entry Grid.Row="0"
           Placeholder="SearchItem"
           TextChanged="Entry_TextChanged"/>
    <Image Grid.Row="1"
           Aspect="Fill"
           Source="testImage.png"/>

        <ListView x:Name="ListView"
                  Grid.Row="1"
                  VerticalOptions="Start"
                  HorizontalOptions="Fill"
                  IsVisible="False"
                  HeightRequest="300"
                  BackgroundColor="White"
                  Opacity="0.8">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextCell Text="{Binding}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

</Grid>

如果搜索条目的文本发生变化,则显示列表视图:

private void Entry_TextChanged(object sender, TextChangedEventArgs e)
    { 
        ListView.IsVisible =  e.NewTextValue.Length > 0; 
    }

在此处输入图片说明

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从Xamarin Forms ListView中删除项目?

Xamarin Forms-如何在ListView中显示/绑定列表?

如何在Xamarin Forms应用程序(android)中仅激活1个ListView项目并禁用其他项目

如何在Xamarin.Forms中的ListView内绑定列表

如何在xamarin.forms中获得ListView的子级?

Xamarin Forms - 如何在 xaml 中创建水平 ListView?

如何在Xamarin.forms xaml中水平显示ListView中的项目?

如何在Xamarin Forms中以2列和n行显示单个listview项目

如何在 Xamarin Forms 中使用 MVVM 在 ListView 中实现增量加载(ItemAppearing)项目?

Xamarin Forms Listview 中的 TapGestureRecognition

如何在Xamarin.Forms中禁用ListView上的突出显示

如何在Xamarin.Forms中基于ListView滚动方向显示和隐藏StackLayout?

Xamarin.Forms:当单击ListView中的项目时,如何显示模态?

Xamarin.Forms禁用ListView中的项目

Xamarin.Forms:StackLayout中的ListView:如何设置高度?

如何更改 Xamarin Forms 中 `ListView` 内 `TextCell` 的背景颜色?

如何在 Xamarin Forms 中删除我的 ListView 中的额外分隔符

如何在ListView Items Xamarin Forms UWP中删除鼠标悬停效果?

如何在Xamarin Forms中的字符串(Listview分组字母)上更改textcolor?

如何在Xamarin.forms中自动向下滚动ListView(MVVM设计模式)

Xamarin Forms:如何在ViewModel中处理Listview图像Click事件?

如何在Xamarin Forms中设置jsonview之前获取json对象并将其设置为listview

C# Xamarin.Forms 如何在 ListView 中获取 Entry.text

无法在 ListView Xamarin Forms 中显示数据

如何在Xamarin Forms中将BackgroundImage添加到ListView?

Xamarin.Forms ListView,如何设置RowHeight?

Xamarin Forms:如何在ListView内绑定Xamarin.forms.Maps的位置值?

Xamarin Forms (Xaml) ListView 不显示图像

Xamarin Forms ListView 文本未显示