Xamarin.Forms 4.4 版本新特性


  最近微軟更新了新版本的xamarin.form4.4框架,這個框架對於當前用戶來說是一大進步,這個框架升級后可以支持更多的新特性,對於開發者來說是一大進步,同時微軟又開始測試新的組件了,另人驚喜的是微軟終於推出了CarouseView和SwipeView兩個重要的組件,而IndicatorView控件只是一個輔助控件,同時開始支持GIF格式的圖片了(以前不支持你敢信,要支持需使用其他的圖庫)。

  要使用新的組件,先使用SetFlage方法聲明一下,在APP.xaml.cs添加如下代碼

 1 public App()
 2 {
 3     InitializeComponent();
 4  
 5     Device.SetFlags(new[] {
 6         "CarouselView_Experimental",
 7         "IndicatorView_Experimental",
 8         "SwipeView_Experimental"
 9     } );
10  
11     MainPage = new AppShell();
12 }

  一、GIF 動圖

<Image Source="https://cataas.com/cat/gif?type=sq" IsAnimationPlaying="True"/>

在Views的xaml中直接添加GIF Image即可,動圖默認是循環播放的,如果要停止循環,設置IsAnimationPlaying為false即可。

  二、CarouseIView 和IndicatorView組件。

  這兩個組件是組合使用的,你可以單獨使用,並不影響功能,CarouseIView是一個巨幕組件,用戶可以滑動巨幕,來切換內容,同時支持水平滑動和垂直滑動,和CollectionView組件類似,但又稍微不同,CollectionView一般用於大量數據的顯示,並且性能非常棒,是微軟推出的替代ListView組件的,而CarouseIView主要是水平巨幕功能。

 1 <CarouselView x:Name="carouselView" ItemsSource="{Binding Monkeys}" >
 2                 <CarouselView.ItemTemplate>
 3                     <!-- DataTemplate that defines item appearance -->
 4                     <DataTemplate>
 5                         <StackLayout>
 6                             <Frame HasShadow="True" BorderColor="DarkGray" CornerRadius="5" Margin="20" HeightRequest="300" HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
 7                                 <StackLayout>
 8                                     <Label Text="{Binding Name}" FontAttributes="Bold" FontSize="Large" HorizontalOptions="Center" VerticalOptions="Center" />
 9                                     <Image Source="{Binding ImageUrl}" Aspect="AspectFill" HeightRequest="150" WidthRequest="150" HorizontalOptions="Center" />
10                                     <Label Text="{Binding Location}" HorizontalOptions="Center" />
11                                     <Label Text="{Binding Details}" FontAttributes="Italic" HorizontalOptions="Center" MaxLines="5" LineBreakMode="TailTruncation" />
12                                 </StackLayout>
13                             </Frame>
14                         </StackLayout>
15                     </DataTemplate>
16                 </CarouselView.ItemTemplate>
17             </CarouselView>
18             <IndicatorView ItemsSourceBy="carouselView"
19                    IndicatorColor="LightGray"
20                    SelectedIndicatorColor="DarkGray"
21                    HorizontalOptions="Center" />

  三、SwipeView組件

  這是一個側滑組件,支持上、下、左、右四個方向的滑動,添加SwipeItem來顯示隱藏的內容,通過SwipView.RightItems、LeftItems、TopItems、BottomItems控制滑動的方向,同時又SwipeStarted、SwipeChanging、SwipedEnded、CloseRequested事件。同時,SwipeView定義了Close方法,用來關閉Items。

 1 <SwipeView>
 2     <SwipeView.LeftItems>
 3         <SwipeItems>
 4             <SwipeItem Text="Favorite"
 5                        IconImageSource="favorite.png"
 6                        BackgroundColor="LightGreen"
 7                        Invoked="OnFavoriteSwipeItemInvoked" />
 8             <SwipeItem Text="Delete"
 9                        IconImageSource="delete.png"
10                        BackgroundColor="LightPink"
11                        Invoked="OnDeleteSwipeItemInvoked" />
12         </SwipeItems>
13     </SwipeView.LeftItems>
14     <!-- Content -->
15 </SwipeView>

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM