How to add style to TableCell .NET MAUI

Louie88 21 Reputation points
2022-09-13T16:47:34.573+00:00

I added a style for TextCell in Styles.xaml file
<Style TargetType="TextCell">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"/>
<Setter Property="DetailColor" Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"/>
</Style>
It does not work. The TableView uses the original .NET purple color.
What do I do wrong?
Thanks,
Louis

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,542 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 31,976 Reputation points Microsoft Vendor
    2022-09-14T09:53:13.337+00:00

    Hello @Louie88 ,

    There is not a Style property for the TextCell . To apply a Style, the target object must be a VisualElement that matches the TargetType property value of the Style, please see Style apps using XAML - .NET MAUI | Microsoft Learn

    However, you can check the inheritance of TextCell : Object ->BindableObject->Element->Cell->TextCell

    If you want to style the TextColor/DetailColor for a TextCell, you have to customize a View cell that contains two Labels for displaying primary and secondary text, so that it looks like a TextCell. Then you can add style to the Label.

    In addition, there is a known issue reported at Xamarin Repo- Bug Setting style on TextCell does not take effect #8755, you could follow the progress.
    (Note: there is no official doc in MAUI, some APIs are Xamarin.Forms )

    Best Regards,
    Wenyan Zhang


    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.