Search code examples
xamarinxamarin.formsmonodevelopxamarin-studioxamarin.mac

How to change Picker background Color in Xamarin MAC Platform


After updating the Xamarin Library and MAC OS to latest system, facing issue in Picker Background color and color of item that is selected/focused in picker for MAC Platform in my visual studio 2017.

Picker that is filled with multiple values

Here is the picture of Picker that is filled with multiple value

On opening the picker can not able to set the background color and the item that is selected is also not visible because of its color

On opening the picker can not able to set the background color and the item that is selected is also not visible because of its color.

How can I set the background color of that picker and the color of that focused/selected item of picker?


Solution

  • This seems to be caused for the new Theme used by Mojave.

    One way to overcome this issue is by setting a value that will be visible on both Light and Dark them, for me it worked the Green.

    Adding this to your XAML should be sufficient

    <Picker.TextColor>
        <OnPlatform x:TypeArguments="Color">
            <On Platform="macOS" Value="Green"/>
        </OnPlatform>
    </Picker.TextColor>
    

    Making the change only on your MacOs project leaving the others as they are.

    <Picker HorizontalOptions="CenterAndExpand" 
            VerticalOptions="CenterAndExpand">
        <Picker.Items>
            <x:String>Dell</x:String>
            <x:String>HP</x:String>
            <x:String>Mac</x:String>
            <x:String>Asus</x:String>
            <x:String>Lenovo</x:String>
            <x:String>Acer</x:String>
            <x:String>Micrsoft</x:String>
        </Picker.Items>
        <Picker.TextColor>
            <OnPlatform x:TypeArguments="Color">
                <On Platform="macOS" Value="Green"/>
            </OnPlatform>
        </Picker.TextColor>
    </Picker>
    

    Note: The TextColor will only affect the selected item text color.

    Hope this helps.-