A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello,
Please add Color itemColor; to your DemyUser.cs like following code.
public partial class DemyUser:ObservableObject
{
[ObservableProperty]
Color itemColor;
...
}
Then you can set the itemColor by the teacher object in the SelectedItem like following code.
[RelayCommand]
void SelectedItem(DemyUser selectedUser)
{
foreach (var teacher in Teachers!)
{
teacher.IsAssignedToCourse = teacher == selectedUser;
if (teacher.IsAssignedToCourse)
{
teacher.ItemColor = Constants.SelectedColor;
}
else
{
teacher.ItemColor=Constants.DefaultUnselectedColor;
}
}
}
In the end, please change the ItemColor's binding way in the <CollectionView>.
<CollectionView.ItemTemplate>
<DataTemplate>
<Border BackgroundColor="{Binding ItemColor}">
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.