2

I have created a ListView with Context actions following these instructions-developer.xamarin.com/guides/xamarin-forms/user-interface/listview/interactivity/#Context_Actions

This is the XAML

<ListView x:Name="ContextDemoList" ItemsSource="{Binding Notes}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.ContextActions>
                    <MenuItem Clicked="OnMore" CommandParameter="{Binding .}" Text="More" />
                    <MenuItem Clicked="OnDelete" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
                </ViewCell.ContextActions>
                <StackLayout Padding="15,5">
                    <Label Text="{Binding Subject}" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Which gives me the context actions fine, but in iOS the buttons get green text. iOS simulator screen cap. The same result is seen when I deploy to a physical device.

I've come across this post https://forums.xamarin.com/discussion/34713/how-to-change-the-menuitem-colors-of-viewlist-in-ios-viewcellrenderer which outlines possible solutions for customizing the MenuItem background color involving custom rendering, reflection, or a plug in which doesn't leverage native elements. But I would prefer to get the native experience cross platform.

Does anyone know where the green text color is coming from? Or if Xamarin has exposed a way to customize this?

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123

1 Answers1

2

Turns out this is part copy paste issue, and part iOS intended functionality.

Setting a UIButton title color will also set the UIMenuItem text color.

namespace Project.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            ...
            // --- offending line of code ---
            UIButton.Appearance.SetTitleColor(UIColor.FromRGB(0, 127, 14), UIControlState.Normal);
            ...
        }
    }
}

There is a solution for customizing both colors for a native iOS app that may have some useful information transferable to Xamarin, Text color in UIMenuController affected by UIButton appearance setting. But I have not attempted to do this.

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123