Venkata Swamy Balaraju

Venkata Swamy Balaraju

  • NA
  • 3.9k
  • 906.2k

How to change BG color for ContextActions in Xamarin.Forms

Sep 13 2018 2:42 AM
Hi guys,
Hope your doing great,
I created ListView with three Context Actions, here I want to set different background color for each MenuItem like below 
 
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <ViewCell xmlns="http://xamarin.com/schemas/2014/forms"  
  3.  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
  4.     x:Class="PureSale.Core.Views.OrdersListTemplate">  
  5.     <Grid Padding="10">  
  6.       <Grid.ColumnDefinitions>  
  7.           <ColumnDefinition Width="*"/>  
  8.           <ColumnDefinition Width="Auto"/>  
  9.         Grid.ColumnDefinitions>  
  10.         <StackLayout Spacing="5">  
  11.            <Label Text="{Binding Title}" FontAttributes="Bold" HorizontalOptions="StartAndExpand"/>  
  12.          <Label Text="{Binding StartDate}" HorizontalOptions="StartAndExpand"/>  
  13.      StackLayout>  
  14.         <Image Source="indicatorIconBlack.png" Grid.Column="1" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand"/>  
  15.     Grid>  
  16. ViewCell>  
  1. public partial class OrdersListTemplate : ViewCell {  
  2.     public OrdersListTemplate(){  
  3.         InitializeComponent();  
  4.   
  5.        var deleteAction = new MenuItem { Text = "Delete", StyleId = "labelRedStyle" };  
  6.         deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));  
  7.         deleteAction.Clicked += (sender, e) => {  
  8.         };  
  9.   
  10.         var archiveAction = new MenuItem { Text = "Archive", IsDestructive = true};   
  11.         archiveAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));  
  12.         archiveAction.Clicked +=  (sender, e) => {  
  13.         };  
  14.   
  15.         var cancelAction = new MenuItem { Text = "Cancel" };  
  16.         cancelAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));  
  17.         cancelAction.Clicked += (sender, e) => {  
  18.         };  
  19.   
  20.     ContextActions.Add(cancelAction);  
  21.             ContextActions.Add(archiveAction);  
  22.             ContextActions.Add(deleteAction);  
  23.    }  
  24.  
 XAML:
  1. <ListView HasUnevenRows="true" ItemsSource="{Binding OrderItems}" ios:ListView.SeparatorStyle="FullWidth" SelectedItem="{Binding SelectedListItem}">  
  2.             <ListView.ItemTemplate>  
  3.                 <DataTemplate>  
  4.                     <views:PartyListTemplate/>  
  5.                 DataTemplate>  
  6.             ListView.ItemTemplate>  
  7. ListView>  
How can I set StyledId for menu item, Please suggest me
Thanks in advance

Answers (1)