Hello,
Infinite loop in SaveCommentOnBlur when Unfocused event is triggered in MAUI
This issue is related to the Listview's item reuse mechanism. SaveCommentOnBlur will be executed repeatedly, if you have over one items in the Listview.
If you want to SaveCommentOnBlur called once when click the entry, you can use BindableLayout.ItemsSource in <Stacklayout>
, it do not have reuse mechanism, it will create MaterialEntry for every item. If you have many items. you want to scroll, you can add <ScrollView>
like following code.
<ContentPage.Content>
<ScrollView Padding="10">
<StackLayout BindableLayout.ItemsSource="{Binding DocumentsList}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Vertical">
<Grid HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" Grid.Column="1">
<control:MaterialEntry Text="{Binding Comments}"
Placeholder="Comment"
Unfocused="SaveCommentOnBlur"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center"/>
</StackLayout>
<Label Text="{Binding Comments}" IsVisible="True"/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<BoxView Margin="0,2,0,2" BackgroundColor="Black" HeightRequest=".5"/>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
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.