单击菜单项时,是否可以在ListView中更改菜单项的文本,例如将其从完整更改为不完整?
答案 0 :(得分:0)
尝试使用ItemTapped事件。
示例应该有效,但我没有测试过。
<强> XAML
<ListView ItemsSource="{Binding MyList}" ItemTapped="OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Vertical">
<Label Text="Incomplete"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<强> C#
public void OnItemTapped (object o, ItemTappedEventArgs e)
{
var listElement = e.Item as ListElement;
if(listItem.Text == "Incomplete")
{
listElement.Text = "Complete";
}
else
listElement.Text = "Incomplete";
}