public AndroidSwipeViewTransitionModePageCS() { StackLayout stackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center }; Label label = new Label { Text = "SwipeTransitionMode: ", VerticalTextAlignment = TextAlignment.Center }; EnumPicker enumPicker = new EnumPicker { EnumType = typeof(SwipeTransitionMode), SelectedIndex = 1 }; enumPicker.SelectedIndexChanged += OnSwipeViewTransitionModeChanged; stackLayout.Children.Add(label); stackLayout.Children.Add(enumPicker); swipeView = new Xamarin.Forms.SwipeView(); SwipeItem swipeItem = new SwipeItem { Text = "Delete", IconImageSource = "delete.png", BackgroundColor = Color.LightPink }; swipeItem.Invoked += OnDeleteSwipeItemInvoked; swipeView.LeftItems = new SwipeItems { swipeItem }; Grid grid = new Grid { HeightRequest = 60, WidthRequest = 300, BackgroundColor = Color.LightGray }; Label gridLabel = new Label { Text = "Swipe right", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center }; grid.Children.Add(gridLabel); swipeView.Content = grid; swipeView.On <Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); Title = "SwipeView SwipeTransitionMode"; Content = new StackLayout { Margin = new Thickness(20), Children = { stackLayout, swipeView } }; }
public SwipeTransitionModeGallery() { Title = "SwipeTransitionMode Gallery"; var scroll = new Xamarin.Forms.ScrollView(); var swipeLayout = new StackLayout { Margin = new Thickness(12) }; var instructions = new Label { BackgroundColor = Color.Black, TextColor = Color.White, Text = "This Gallery use a Platform Specific only available for Android and iOS." }; swipeLayout.Children.Add(instructions); var swipeItemSwipeTransitionModeLabel = new Label { FontSize = 10, Text = "SwipeTransitionMode:" }; swipeLayout.Children.Add(swipeItemSwipeTransitionModeLabel); var swipeItemSwipeTransitionModePicker = new Xamarin.Forms.Picker(); var swipeTransitionModes = Enum.GetNames(typeof(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode)).Select(t => t).ToList(); swipeItemSwipeTransitionModePicker.ItemsSource = swipeTransitionModes; swipeItemSwipeTransitionModePicker.SelectedIndex = 0; // Reveal swipeLayout.Children.Add(swipeItemSwipeTransitionModePicker); var deleteSwipeItem = new SwipeItem { BackgroundColor = Color.Red, IconImageSource = "delete.png", Text = "Delete" }; deleteSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Delete Invoked", "Ok"); }; var swipeItems = new SwipeItems { deleteSwipeItem }; swipeItems.Mode = SwipeMode.Reveal; var leftSwipeContent = new Grid { BackgroundColor = Color.Gray }; var leftSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Right" }; leftSwipeContent.Children.Add(leftSwipeLabel); var leftSwipeView = new Xamarin.Forms.SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = swipeItems, Content = leftSwipeContent }; swipeLayout.Children.Add(leftSwipeView); var rightSwipeContent = new Grid { BackgroundColor = Color.Gray }; var rightSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Left" }; rightSwipeContent.Children.Add(rightSwipeLabel); var rightSwipeView = new Xamarin.Forms.SwipeView { HeightRequest = 60, WidthRequest = 300, RightItems = swipeItems, Content = rightSwipeContent }; swipeLayout.Children.Add(rightSwipeView); var topSwipeContent = new Grid { BackgroundColor = Color.Gray }; var topSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Top" }; topSwipeContent.Children.Add(topSwipeLabel); var topSwipeView = new Xamarin.Forms.SwipeView { HeightRequest = 60, WidthRequest = 300, BottomItems = swipeItems, Content = topSwipeContent }; swipeLayout.Children.Add(topSwipeView); var bottomSwipeContent = new Grid { BackgroundColor = Color.Gray }; var bottomSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Bottom" }; bottomSwipeContent.Children.Add(bottomSwipeLabel); var bottomSwipeView = new Xamarin.Forms.SwipeView { HeightRequest = 60, WidthRequest = 300, TopItems = swipeItems, Content = bottomSwipeContent }; swipeLayout.Children.Add(bottomSwipeView); swipeItemSwipeTransitionModePicker.SelectedIndexChanged += (sender, e) => { var swipeTransitionMode = swipeItemSwipeTransitionModePicker.SelectedItem; switch (swipeTransitionMode) { case "Drag": leftSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Drag); leftSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Drag); rightSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Drag); rightSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Drag); topSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Drag); topSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Drag); bottomSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Drag); bottomSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Drag); break; case "Reveal": leftSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Reveal); leftSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Reveal); rightSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Drag); rightSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Drag); topSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Drag); topSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Drag); bottomSwipeView.On <Android>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.AndroidSpecific.SwipeTransitionMode.Drag); bottomSwipeView.On <iOS>().SetSwipeTransitionMode(Xamarin.Forms.PlatformConfiguration.iOSSpecific.SwipeTransitionMode.Drag); break; } }; scroll.Content = swipeLayout; Content = scroll; }