c# - Xamarin Forms C# ListView 搜索
问题描述
Xamarin Forms C# ListView 搜索
大家好,当我按名称进行过滤时,我想从 ListView 进行搜索我希望建议出现在 listview 中我尝试这样做但对我不起作用!我不明白是什么问题..
问题截图:https ://i.imgur.com/vhpt8Cp.jpg
Xamarin Forms C# ListView Search
大家好,当我按名称进行过滤时,我想从 ListView 进行搜索我希望建议出现在列表视图中我试图这样做但对我不起作用!我不明白是什么问题..
Model> echeance.cs:
------------
namespace Appz.Model
{
public class Echeance
{
[PrimaryKey, AutoIncrement]
public int ChkId { get; set; }
public string ChkChoise { get; set; }
[MaxLength(50)]
public string ChkNumber { get; set; }
public string ChkAmount { get; set; }
[MaxLength(50)]
public string BeneficiaryName { get; set; }
public string AgencyType { get; set; }
public DateTime ChkDueDate { get; set; }
public DateTime ChkReleaseDate { get; set; }
public string ChkImage { get; set; }
}
}
EcheanceView.Xaml:
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true"
x:Class="Appz.View.EcheanceView">
<ContentPage.Content>
<StackLayout Padding="10,0,10,0">
<SearchBar TextChanged="Handle_TextChanged"></SearchBar>
<ListView ItemsSource="{Binding EcheancesList}" IsPullToRefreshEnabled="True" x:Name="ListEcheances" HasUnevenRows="true" SeparatorVisibility="Default" ItemTapped="OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Image Source="{Binding ChkImage}" HeightRequest="50" WidthRequest="50" />
<StackLayout HorizontalOptions="StartAndExpand">
<Label Text="{Binding BeneficiaryName}"
FontAttributes="Bold" />
<Label Text="{Binding AgencyType}"
TextColor="Gray" />
</StackLayout>
<Button Text="Follow Me"
BorderColor="Silver"
FontSize="Small"
TextColor="White"
BackgroundColor="#3399ff"
VerticalOptions="Center"
/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
EcheanceView.cs:
---------------
void Handle_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e)
{
using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
{
var echeances = conn.Table<Echeance>().ToList();
//ListEcheances.ItemsSource = echeances;
if (string.IsNullOrWhiteSpace(e.NewTextValue))
ListEcheances.ItemsSource = echeances;
else
ListEcheances.ItemsSource = echeances.Where(i => i.BeneficiaryName.Contains(e.NewTextValue));
ListEcheances.EndRefresh();
}
}
有人帮助我请提前谢谢!
解决方案
在您的情况下,似乎某些项目的 BeneficiaryName 为空。
推荐阅读
- javascript - 如何在Javascript中验证剪贴板是否为空?
- angularjs - 如何为confirmButton和cancelButton sweetalert2 angular js添加id
- java - 在 Jenkins 上构建项目时收到 AIDL RunTimeException 但使用 AndroidStudio 构建成功
- iis - IIS 将根目录重定向到具有 SSL 域的子目录
- asp.net-mvc - ASP .NET MVC Identity 用户多个组,多个角色
- python - 带有 .x .y 坐标的 Python 模仿 ASPX 请求
- jenkins - 当我在 jenkins 上运行我的项目时,它似乎使用我的其他 officemate 帐户登录到 ssh,然后它关闭并且从不阅读我的测试用例
- python - 对第一行和第一列矩阵求和
- php - 函数 route() 的参数太少,
- javascript - 关于console.log in while循环的问题