언어 설정

Menu
Sites
Language
CollectionView Xamarin.Forms how fire event on Highlighted/Selected Item?

Hello,
In the old xamarin forms (<= 4.8) I used a "Button" and its properties Focus/Clicked/etc.. To access the element, and modify its preview, such as changing the background or other.

Since the new version of xamarin.forms ( >= 5.X) I am unable to use the collectionview correctly?

No focus/highlight on the element?

Ideas? tips? are welcome.

Thanks

 

Work in older version but not newer:

<CollectionView ItemSizingStrategy="MeasureFirstItem" SelectionMode="Single" ItemsSource="{Binding List}" ItemTemplate="{StaticResource Template}">
    <CollectionView.ItemsLayout>
         <LinearItemsLayout Orientation="Vertical"/>
    <CollectionView.ItemsLayout>
    
    <DataTemplate x:Key="Template">
        <AbsoluteLayout HeightRequest="74" WidthRequest="960">
            <BoxView Opacity="0" CornerRadius="0,40,0,40" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"/>
            <Label FontSize="40" AbsoluteLayout.LayoutBounds="10,25,80,50" TextColor="White" Text="{Binding Num,Mode=OneTime}" LineBreakMode="NoWrap"/>
            <Label AbsoluteLayout.LayoutBounds="220,.5" AbsoluteLayout.LayoutFlags="YProportional" Text="{Binding Title,Mode=OneTime}" FontSize="55" LineBreakMode="NoWrap"/>
            <Button Opacity="0" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" Focused="OnItemFocused" Unfocused="OnItemUnFocused" Clicked="OnItemClicked" />            
        </AbsoluteLayout>
    </DataTemplate>

 

Responses

1 댓글
Sung-su Kim

Hi,

There are many ways, but how about a below sample code?

https://github.com/xamarin/xamarin-forms-samples/blob/main/UserInterface/CollectionViewDemos/CollectionViewDemos/Views/Selection/VerticalListSelectionColorPage.xaml

Thanks.