gpt4 book ai didi

c# - Xamarin forms 单击一次显示上下文菜单

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:34 24 4
gpt4 key购买 nike

我已经成功地通过长按创建了上下文菜单,并尝试在 C# 代码中使用 ListView 中的单个菜单使其工作。

示例 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:local="clr-namespace:App2.Services"
x:Class="App2.Views.Clients.ClientsPage">
<ContentPage.Content>

<ListView x:Name="clientList" ItemsSource="{x:Static
local:ClientService.ClientsGrouping}"
IsGroupingEnabled="True"
HasUnevenRows="True"
SeparatorVisibility="Default"
GroupShortNameBinding="{Binding GroupByShortName}">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<!--<TextCell Text="{Binding GroupByTitle}" />-->
<ViewCell Height="30">
<ContentView>
<Label FontSize="Medium" FontFamily="bold" Text="
{Binding GroupByTitle}" BackgroundColor="LightGray"/>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>

<!--<TextCell Text="{Binding FullName}" Detail="{Binding
Email}" />-->

<ViewCell Height="100">

<ViewCell.ContextActions>
<MenuItem x:Name="callAction" Text="Call"
Clicked="callAction_Clicked" />
<MenuItem x:Name="emailAction" Text="Email"
Clicked="emailAction_Clicked" />
<MenuItem x:Name="viewProfileAction" Text="Profile"
Clicked="viewProfileAction_Clicked" />
</ViewCell.ContextActions>

<ContentView Margin="10">

<Grid RowSpacing="0">

<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>


<StackLayout Orientation="Vertical"
Grid.Row="0" Grid.Column="0">
<Label Text="{Binding FullName}"></Label>
</StackLayout>
<Label Text="{Binding Email}" Grid.Row="1"
Grid.Column="0"></Label>
<!--<Button x:Name="clientContextMenu"
Text="..." Grid.Row="0" Grid.Column="1" Clicked="clientContextMenu_Clicked">
</Button>-->
<Image Source="menu_more.png" Grid.Row="0"
Grid.Column="1"/>
</Grid>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>

我知道如何触发 listview 项目选择事件,但是当单击项目时显示上下文菜单不太确定如何实现。

最佳答案

 <Viewcell.ContextActions>
<MenuItem x:Name="MenuItem" Clicked="OnClicked" Text="{Binding Text}" CommandParameter="{Binding Name}" IsDestructive=false/>
</Viewcell.ContextActions>

您是否尝试过滑动菜单项然后单击而不是您所做的。

关于c# - Xamarin forms 单击一次显示上下文菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46159140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com