I have ListView using custom template. How do I highlight selected item or tabbed item without using code-behind ?
View
<StackLayout
Grid.Row="1"
BackgroundColor="#21576C"
HorizontalOptions="StartAndExpand"
VerticalOptions="StartAndExpand">
<StackLayout
BackgroundColor="#134359"
Margin="5,5,5,5">
<ListView x:Name="Catagoris"
HorizontalOptions="Start"
VerticalOptions="FillAndExpand"
BackgroundColor="Transparent"
HasUnevenRows="True"
ItemsSource="{Binding CatagoryType}"
ItemSelected="ListView_OnItemSelected"
MinimumHeightRequest="100"
SeparatorVisibility="None"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label x:Name="ListViewLabel"
HorizontalOptions="FillAndExpand"
HorizontalTextAlignment="Center"
VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
TextColor="#3C9DC5"
Text="{Binding ., Converter={StaticResource SpaceOnUpperAndStringToUpperCaseConverter}}"
HeightRequest="50">
</Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</StackLayout>
Prop in VM
public bool IsCatagorySelected
{
get { return _isCatagorySelected; }
set
{
if (_isCatagorySelected != value)
{
OnPropertyChanging(()=>IsCatagorySelected);
_isCatagorySelected = value;
OnPropertyChanged(() => IsCatagorySelected);
}
}
}
Code behind
private void ListView_OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
MyViewModel myViewModel= sender as MyViewModel;
if (e.SelectedItem == null)
{
return;
}
myViewModel.IsCatagorySelected= true;
DisplayAlert("Item Selected", e.SelectedItem.ToString(), "OK");
}
I need to change the background color and text color of Label 'ListviewLabel'.