How to bind data properly to user control if it's inside a ListView's DataTemplate?

Sunshine 46 Reputation points

Hello everyone,

In MAUI, as instructed by ContentView doc, we can define user controls for reusability.

However, since it requires specifying Source when binding, I don't know how to bind data for it if it is inside a DataTemplate of ListView.


Here is the link of [demo project]("demo project") .  Thanks.

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,045 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 70,556 Reputation points Microsoft Vendor


    You can do this by moving BindingContext="{x:Reference thisUC}" to the <Stacklayout> and no need to set Reference for Label's binding property again, you can refer to following xaml code.

    <ContentView xmlns=""
        <StackLayout  BindingContext="{x:Reference thisUC}" >
            <Label Text="{Binding CardTitle}" FontSize="20" BackgroundColor="Gray" Margin="5"/>

    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.

0 additional answers

Sort by: Most helpful