xamarin.forms_Xamarin.Forms 4.4助您一臂之力

xamarin.forms

CarouselView control in Xamarin.Forms 4.4.0. Along with this we also have  CarouselView控件。 除此之外,我们还具有 IndicatorView for displaying the pages or items in the carousel. As well as  IndicatorView用于显示轮播中的页面或项目。 以及 SwipeView for providing contextual actions to any element in a  SwipeView用于为 CollectionView. The release theme of getting things moving would not be complete without showcasing the new GIF animation support for images. Let’s begin right there. CollectionView任何元素提供上下文操作。 如果不展示对图像的新GIF动画支持,那么使事情动起来的发行主题将是不完整的。 让我们从那里开始。

Xamarin.Forms 4.4功能 (Xamarin.Forms 4.4 Features)

GIF animations are a great and simply way to add animation to your app for better user feedback, calling attention to some action or detail. It’s also great for cat GIFs, of course. The Image is all you need along with the new IsAnimationPlaying property to enable and disable playback.

GIF动画是一种将动画添加到您的应用中的绝佳方法,可以更好地吸引用户,引起人们对某些动作或细节的注意。 当然,这对于cat GIF也很棒。 您只需拥有Image以及新的IsAnimationPlaying属性即可启用和禁用播放。

Animations will loop by default. To stop an animation, set IsAnimationPlaying to false.

动画将默认循环播放。 要停止动画,请将IsAnimationPlaying设置为false。

Just like that you have animations! This is ideal for smaller images, and especially those embedded in your application. Looping settings in the GIF image are respected. Make sure you are using fast renderers on Android for the best experience.

就像您有动画一样! 对于较小的图像,特别是嵌入在应用程序中的图像,这是理想的选择。 遵守GIF图像中的循环设置。 确保您在Android上使用快速渲染器以获得最佳体验。

CarouselView和IndicatorView (CarouselView and IndicatorView)

Built upon the same base control as CollectionView, the new CarouselView makes it simple to add rich carousels to your app no matter whether you’re scrolling horizontally or vertically. Just as you get with CollectionView you get:

基于与CollectionView相同的基本控件,新的CarouselView使您可以轻松地向应用程序添加丰富的轮播,无论您是水平滚动还是垂直滚动。 就像使用CollectionView您将获得:

  • ItemsLayout

    ItemsLayout
  • ItemsSource

    ItemsSource
  • ItemTemplate

    ItemTemplate
  • EmptyTemplate

    空模板
<CarouselView HeightRequest="160">
    <CarouselView.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>h01.jpg</x:String>
            <x:String>h02.jpg</x:String>
            <x:String>h03.jpg</x:String>
            <x:String>h04.jpg</x:String>
        </x:Array>
    </CarouselView.ItemsSource>
    <CarouselView.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding .}"/>
        </DataTemplate>
    </CarouselView.ItemTemplate>
</CarouselView>

You also get some carousel specific properties for controlling things such as the distance the previous and next items should «peek» into view.

您还可以获得一些特定于轮播的属性,用于控制事物,例如,上一个和下一个项目应“窥视”的距离。

<CarouselView PeekAreaInsets="50"
              ...>

Advanced Tip: In the example above you’ll also note that the previous and next items are scaled and offset. You can achieve this today with a behavior and doing the layout modifications on scroll. When we ship 4.5 you’ll instead be able to use visual states to more easily do this.

高级提示:在上面的示例中,您还将注意到上一个和下一个项目是缩放和偏移的。 今天,您可以通过行为并在滚动上进行布局修改来实现此目的。 当我们发货4.5时,您将可以使用视觉状态更轻松地执行此操作。

To add an IndicatorView you position it wherever you like and then associate it to the CarouselView by name:

要添加一个IndicatorView您可以将其放置在IndicatorView位置,然后按名称将其与CarouselView关联:

<CarouselView x:Name="walletCarousel">
// implementation here
</CarouselView>
<IndicatorView 
  IndicatorColor="LightGray"
  SelectedIndicatorColor="Black"
  IndicatorSize="10" HorizontalOptions="Center"
  IndicatorView.ItemsSourceBy="walletCarousel"/>

For more details about all the powerful things you can do with CarouselView and IndicatorView, refer to the documentation.

有关CarouselViewIndicatorView可以执行的所有功能的更多详细信息,请参阅文档

Note: The previously released NuGet Xamarin.Forms.CarouselView (Preview) will be archived and no longer released. If you were using this control, you may remove the NuGet and update your code namespace. We worked to keep the API consistent, but you may need to adjust a few things. GitHub

注意:先前发布的NuGet Xamarin.Forms.CarouselView(预览)将被存档,不再发布。 如果使用此控件,则可以删除NuGet并更新代码名称空间。 我们努力保持API的一致性,但是您可能需要调整一些内容。 的GitHub

滑动查看 (SwipeView)

This control is typically found within a list of items for allowing the user to swipe in any direction to reveal context buttons for common actions like edit or delete. In order to use this control, just wrap it around whatever element you wish to add the behavior to, and specific your SwipeItems. By default a SwipeItem takes a title and an icon, plus a command or click handler. If you wish to add something more complex, you can do that via a template.

通常在项目列表中找到此控件,以允许用户向任意方向滑动以显示上下文按钮以执行诸如编辑或删除之类的常见操作。 为了使用此控件,只需将其包装在您希望向其添加行为的任何元素周围,并指定您的SwipeItems。 默认情况下, SwipeItem带有标题和图标,以及命令或单击处理程序。 如果您想添加更复杂的内容,可以通过模板来完成。

<SwipeView>
        <SwipeView.RightItems>
                <SwipeItems Mode="Execute">
                        <SwipeItem Text="Favourite" Command="{Binding Favourite}">
                                <SwipeItem.Icon>
                                        <FontIconSource Glyph=""/>
                                </SwipeItem.Icon>
                        </SwipeItem>
                </SwipeItems>
        </SwipeView.LeftItems>
 
        <!-- Swipeable content -->
        <Frame>
          // content here
        </Frame>
</SwipeView>

The above sample and more were blogged by our talented team member Javier Suarez Ruiz.

上面的示例和更多内容是由我们才华横溢的团队成员Javier Suarez Ruiz撰写的。

You can also use platform-specifics to control the swipe transition mode on Android and iOS. For more details about SwipeView, refer to the documentation.

您还可以使用特定于平台的功能来控制AndroidiOS上的滑动转换模式。 有关SwipeView更多详细信息,请参阅文档

贡献者 (Contributors)

Even before the massive turnout for Hacktoberfest we had a lot of fantastic contributions in the pipeline that are now appearing in Xamarin.Forms 4.4.0. Check out these great improvements from 34 of your fellow developers. Highlights include:

甚至在Hacktoberfest大规模投票之前,我们已经在管道中做出了许多惊人的贡献,这些贡献现在已经出现在Xamarin.Forms 4.4.0中。 从您的34个其他开发人员中查看这些巨大的改进 。 重点包括:

Xamarin.Forms 4.4入门 (Get Started with Xamarin.Forms 4.4 Today)

To get started with Xamarin.Forms 4.4, update or install from your favorite NuGet package manager. The transition from 4.3.0 is smooth. If you are updating from a previous version, take note that Xamarin.Forms and Xamarin.Essentials now depend on Android Support 28.0.0.3. So you will want to update those together along with any other packages you use that might depend on the Android Support libraries.

要开始使用Xamarin.Forms 4.4,请从您喜欢的NuGet软件包管理器更新或安装。 从4.3.0过渡很顺利。 如果您要从以前的版本进行更新,请注意Xamarin.Forms和Xamarin.Essentials现在依赖于Android支持28.0.0.3。 因此,您将希望将其与可能依赖于Android支持库的所有其他软件包一起更新。

Make sure to enable the new preview features using SetFlags if you wish to use them. To do this globally for all platforms in your solution, add the following in your App.xaml.cs:

如果您想使用SetFlags请确保启用它们。 要针对解决方案中的所有平台全局执行此操作,请在App.xaml.cs添加以下内容:

public App()
{
    InitializeComponent();
 
    Device.SetFlags(new[] { 
        "CarouselView_Experimental", 
        "IndicatorView_Experimental",
        "SwipeView_Experimental" 
    } );
 
    MainPage = new AppShell();
}

We will be watching GitHub for your feedback on these preview controls between now and our next version, 4.5 when we expect to move them swiftly out of this preview state.

从现在开始到我们的下一个版本4.5,我们将在GitHub上收到您对这些预览控件的反馈,我们希望将它们快速移出此预览状态。

翻译自: https://habr.com/en/company/microsoft/blog/480038/

xamarin.forms

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值