我正在尝试创建此ContentView,它将根据ClassID从数据库中获取不同的列。在显示正确的数据时出现问题。我不确定我的方法是否正确?我可以使用变量cType更改ViewCell中标签的绑定
我如何称呼ContentView
<local:AutoCompleteEntry
x:Name="vBrand"
ClassId="brand"
/>
<local:AutoCompleteEntry
x:Name="vPart"
ClassId="part"
/>
XAML
<StackLayout Orientation="Vertical" BackgroundColor="AliceBlue">
<Entry TextChanged="searchBar_TextChanged"
BackgroundColor="#f9f9f9"
TextColor="#FF464859"
Unfocused="searchBar_Unfocused"
FontSize="16" PlaceholderColor="#646b7a"
x:Name="searchBar"
Placeholder="Type here..."/>
<ListView x:Name="lvw" IsVisible="False"
CachingStrategy="RecycleElement"
BackgroundColor="White"
ItemTapped="lvw_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame>
<StackLayout BackgroundColor="White">
<Label Text="{Binding ctype}" FontSize="16" TextColor="Black"/>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
[CODE] >>
ObservableCollection<Item> collection;
SqliteDB<Item> dbItem = new SqliteDB<Item>(unique.dbPath);
String ctype="";
private async Task initLvw()
{
ctype = ClassId;
switch (ClassId)
{
case "brand":
collection = await dbItem.ReadData(e=>e.brand.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.brand);
break;
case "part":
collection = await dbItem.ReadData(e => e.partno.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.partno);
break;
case "plgrp":
collection = await dbItem.ReadData(e => e.plgrp.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.plgrp);
break;
case "itemname":
collection = await dbItem.ReadData(e => e.itemname.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.itemname);
break;
}
lvw.EndRefresh();
}
我正在尝试创建此ContentView,它将根据ClassID从数据库中获取不同的列。在显示正确的数据时出现问题。我不确定我的...
因为我只需要在列表视图中显示1列,所以我添加了一个新列表来处理ObjectCollection中的结果。这样,我就不需要更改绑定。