【问题标题】:Xamarin forms Show Context Menu on single ClickXamarin 表单在单击时显示上下文菜单
【发布时间】:2017-09-13 20:46:08
【问题描述】:

我已经设法通过长按创建上下文菜单,尝试在 C# 代码中使用列表视图上的单个菜单使其工作。

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 item selected 事件,但在单击项目时显示上下文菜单并不确定如何实现。

【问题讨论】:

    标签: c# xamarin.forms


    【解决方案1】:
     <Viewcell.ContextActions>
                        <MenuItem x:Name="MenuItem"  Clicked="OnClicked" Text="{Binding Text}"   CommandParameter="{Binding Name}" IsDestructive=false/>
                      </Viewcell.ContextActions>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-08
      • 2010-09-21
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 2017-05-13
      相关资源
      最近更新 更多