简体   繁体   中英

How do I animate an element inside the collectionview in xamarin.forms

I want to bind the rotate animation on an element which is inside the collectionview, if there is a way to animate it with only xaml then it wouldn't be the problem but in Xamarin.form we have to reference the object then animate it with C# like this await lable.RotateTo (360, 2000); . How do I do the same to an object which is inside the collectionview creating dynamically.

Here the example code, I want to rotate iconize:IconLabel (Just a Label with an icon)

<CollectionView x:Name="MyCollectionView"
                ItemsSource="{Binding MyCollection}"
                SelectionMode="Single">
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <StackLayout>
                <iconize:IconLabel
                    WidthRequest="46"
                    Text="far-sync"
                    FontSize="26"
                    TextColor="{StaticResource Key=AccentColor}" />
            </StackLayout>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

There is also a Bindable Rotate property on Label should I use that instead?

PS: It would be very easy if somehow iconize:IconLabel can be binded to a property in MyCollection then I would loop through all the elements and bind the animation to it.

Like @Cfun said, Rotate property would work for you. But please note that, the Rotation property would roate once when you load the app. If you wanna more for this, you still need do something in the code behind.

 <Label
            HorizontalOptions="CenterAndExpand"
            Rotation="250"
            Text="Welcome to Xamarin.Forms!"
            VerticalOptions="CenterAndExpand" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM