简体   繁体   English

如何为 xamarin.forms 中的集合视图内的元素设置动画

[英]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); 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# 像这样await lable.RotateTo (360, 2000); . . How do I do the same to an object which is inside the collectionview creating dynamically.如何对动态创建的 collectionview 中的 object 执行相同操作。

Here the example code, I want to rotate iconize:IconLabel (Just a Label with an icon)这里的示例代码,我要旋转iconize:IconLabel (只是一个带有图标的 Label)

<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? Label上还有一个 Bindable Rotate属性,我应该改用它吗?

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. PS:如果以某种方式iconize:IconLabel可以绑定到MyCollection中的属性,那将非常容易,然后我将遍历所有元素并将 animation 绑定到它。

Like @Cfun said, Rotate property would work for you.就像@Cfun 说的, Rotate属性会为你工作。 But please note that, the Rotation property would roate once when you load the app.但请注意,当您加载应用程序时,Rotation 属性会旋转一次。 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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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