我是xamarin的新手,
当我在列表视图中选择一个项目但无法正常工作时,我试图显示一个对话框警报
这里是我的xaml代码:
<!-- Overlay WordList -->
<ContentView x:Name="WordListView" >
<StackLayout Padding="0,10,0,0">
<ListView x:Name="WordSList"
ItemSelected="OnSelectedTestHelp"
HasUnevenRows="True"
IsPullToRefreshEnabled="true"
Refreshing="OnRefresh" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell >
<ViewCell.ContextActions>
<MenuItem Clicked="OnUpdate" Text="Update" CommandParameter="{Binding .}"/>
<MenuItem Clicked="OnComplete" Text="Delete" CommandParameter="{Binding .}"/>
</ViewCell.ContextActions>
<StackLayout Padding="10,5,5,5" VerticalOptions="StartAndExpand" Orientation="Vertical">
<Label TextColor="Black" Text="{Binding Vocabulary}" FontSize="15" />
<Label TextColor="Black" Text="{Binding Reminder}" FontSize="12" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentView>
<!-- END Overlay WordList -->
这是我的代码,其功能为“ OnSelectedTestHelp”:
public void OnSelectedTestHelp(object sender, ItemTappedEventArgs e)
{
DisplayAlert("Help ! ", "Reminder :", "✔");
Console.WriteLine("####");// I can see this out put
}
对不起我的新手问题
答案 0 :(得分:1)
具有“ OnSelectedTestHelp”功能的代码,那里存在问题:
public void OnSelectedTestHelp(object sender, SelectedItemChangedEventArgs e)
{
DisplayAlert("Help ! ", "Reminder :", "✔");
Console.WriteLine("####");// I can see this out put
}
由于您在xaml中添加的属性为ItemSelected="OnSelectedTestHelp"
,因此应在函数中使用SelectedItemChangedEventArgs
。
如果您在xaml中使用ItemTapped="xxx"
,则函数中将使用ItemTappedEventArgs
。
public event EventHandler<Xamarin.Forms.SelectedItemChangedEventArgs> ItemSelected;
public event EventHandler<Xamarin.Forms.ItemTappedEventArgs> ItemTapped;
您可以参考this demo