I’m experiencing an issue with changing the background color of selected items in my Xamarin.Forms application. Despite my efforts, the background color does not change as expected, and it seems like the default orange highlight is hardcoded somewhere deep in the Xamarin.Forms project.
We attempted to change the background color of a selected Frame within a Xamarin.Forms ListView. Specifically, our goal was to use data binding and a BooleanToColorConverter to dynamically update the background color based on the selection state of the item. However, despite our efforts, the selected Frame continues to default to an orange highlight, which appears to be set by some underlying style or default behavior within the Xamarin.Forms framework.
orange button
origin
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:MentalTest.Views"
x:Class="MentalTest.Views.NewSurveyPage"
Title="{Binding CurrentQuestion.QuestionText}"
NavigationPage.HasNavigationBar="False">
<ContentPage.Content>
<AbsoluteLayout>
<!-- Background shapes -->
<Image Source="VectorBlue.png"
AbsoluteLayout.LayoutBounds="0.5, 1.2, 1, 1"
AbsoluteLayout.LayoutFlags="All"
Aspect="AspectFill" />
<Image Source="VectorOrange.png"
AbsoluteLayout.LayoutBounds="0.5, 1.5, 1, 1"
AbsoluteLayout.LayoutFlags="All"
Aspect="AspectFill" />
<!-- Content -->
<Grid AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Header -->
<StackLayout Orientation="Horizontal"
BackgroundColor="White"
HeightRequest="50"
Padding="10"
VerticalOptions="Start"
Grid.Row="0">
<ImageButton Source="back_arrow.png"
HorizontalOptions="Start"
VerticalOptions="Center"
WidthRequest="36"
HeightRequest="36"
BackgroundColor="Transparent"
Rotation="180"
Clicked="OnBackButtonClicked" />
<Label Text="Back to Test Cards"
FontSize="24"
FontAttributes="Bold"
HorizontalOptions="Start"
VerticalOptions="Center"
TextColor="#394758"
Margin="10,0,0,0" />
</StackLayout>
<!-- Content -->
<StackLayout Padding="20"
VerticalOptions="FillAndExpand"
Grid.Row="1">
<Label Text="{Binding QuestionCounterText}"
FontSize="16"
TextColor="#394758"
HorizontalOptions="Center" />
<!-- Question and Answers -->
<StackLayout Spacing="20"
VerticalOptions="FillAndExpand">
<Label Text="{Binding CurrentQuestion.QuestionText}"
FontSize="20"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Start"
TextColor="#394758"
Margin="0,20,0,20" />
<ListView ItemsSource="{Binding CurrentAnswers}"
SelectedItem="{Binding SelectedAnswer}"
SeparatorVisibility="None"
BackgroundColor="Transparent"
VerticalOptions="FillAndExpand"
Margin="0,20,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" Padding="0">
<Frame BorderColor="#b76e79"
CornerRadius="30"
Padding="6"
Margin="10,10,10,15"
BackgroundColor="White"
HasShadow="True"
HeightRequest="100"
VerticalOptions="CenterAndExpand">
<Label Text="{Binding .}"
FontSize="16"
TextColor="#394758"
VerticalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"/>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</StackLayout>
<!-- Continue Button -->
<Button Command="{Binding ContinueCommand}"
Text="Continue"
HorizontalOptions="FillAndExpand"
VerticalOptions="End"
HeightRequest="50"
Margin="20,10"
BackgroundColor="#4A90E2"
TextColor="White"
CornerRadius="25"
Grid.Row="2"
IsEnabled="{Binding SelectedAnswer}" />
</Grid>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
zombie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.