【发布时间】:2021-08-05 05:32:52
【问题描述】:
我有一个输入 ID 的字段和一个行读取按钮。 当您输入 ID 并单击按钮时,会出现一条消息,其中包含相应行上的信息。 我想删除“读取”按钮和输入字段,以便当用户单击相应的行时,将显示一条包含该行信息的消息?
我的 xaml.cs 代码是:
async void ReadCity()
{
if (!string.IsNullOrEmpty(txtPersonId.Text))
{
//Get Person
var person = await App.SQLiteDb.GetItemAsync(Convert.ToInt32(txtPersonId.Text));
if (person != null)
{
await DisplayAlert("Success", "Person Name: " + person.Name, "OK");
}
}
else
{
await DisplayAlert("Required", "Please Enter PersonID", "OK");
}
}
void BtnRead_Clicked(System.Object sender, System.EventArgs e)
{
ReadCity();
}
我的 xaml 代码是:
<StackLayout HorizontalOptions="Center" VerticalOptions="Start">
<Label Margin="0,0,0,10" Text="FAVORITES" FontAttributes="Bold" FontSize="Large" TextColor="Gray" HorizontalTextAlignment="Center" ></Label>
<Entry x:Name="txtPersonId" Placeholder="City ID for Delete"></Entry>
<StackLayout HorizontalOptions="CenterAndExpand" Orientation="Horizontal">
<Button x:Name="btnDelete" WidthRequest="200" Text="Delete" Clicked="BtnDelete_Clicked" />
<Button x:Name="btnRead" WidthRequest="200" Text="Read" Clicked="BtnRead_Clicked" />
</StackLayout>
<ListView x:Name="lstPersons">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding PersonID}"></TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
有没有办法删除读取按钮并获取相对于按下行的 ID?
【问题讨论】: