Skip to content

Instantly share code, notes, and snippets.

View jfversluis's full-sized avatar

Gerald Versluis jfversluis

View GitHub Profile
// Other code here...
// DO NOT use this code, it's faulty
global::Xamarin.Forms.Forms.SetFlags("CarouselView_Experimental");
global::Xamarin.Forms.Forms.SetFlags("IndicatorView_Experimental");
// Other code here...
public partial class FavFightersView : ContentPage
{
public FavFightersView()
{
InitializeComponent();
BindingContext = new FavFightersViewModel();
// Catch the message here and show the alert
MessagingCenter.Subscribe<Fighter>(this, "Favorited", (f) =>
{
public class FavFightersViewModel : BindableObject
{
ObservableCollection<Fighter> _fighters;
// Added this...
public Command<Fighter> FavoriteCommand { get; set; }
public FavFightersViewModel()
{
LoadFighters();
<SwipeItemView Command="{Binding Path=BindingContext.FavoriteCommand, Source={x:Reference Name=FightersPage}}" CommandParameter="{Binding .}">
<Grid
WidthRequest="120"
BackgroundColor="{StaticResource BackgroundColor}">
<BoxView
Style="{StaticResource SwipeItemBorderStyle}"/>
<Image
Source="star.png"
Style="{StaticResource SwipeItemIconStyle}"/>
<Label
public partial class FavFightersView : ContentPage
{
public FavFightersView()
{
InitializeComponent();
BindingContext = new FavFightersViewModel();
}
// !!!!! This is the important part, right here !!!!!
void SwipeItemView_Invoked(System.Object sender, System.EventArgs e)
<!-- Note the added Invoked attribute here -->
<SwipeItemView Invoked="SwipeItemView_Invoked">
<Grid
WidthRequest="120"
BackgroundColor="{StaticResource BackgroundColor}">
<BoxView
Style="{StaticResource SwipeItemBorderStyle}"/>
<Image
Source="star.png"
Style="{StaticResource SwipeItemIconStyle}"/>
<DataTemplate x:Key="MessageTemplate">
<SwipeView
HeightRequest="110">
<SwipeView.RightItems>
<SwipeItems
Mode="Reveal">
<SwipeItemView>
<Grid
WidthRequest="120"
BackgroundColor="{StaticResource BackgroundColor}">
@jfversluis
jfversluis / MainPage.xaml
Created December 16, 2019 14:54
SwipeView in Action
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SwipeViewSample.MainPage">
<StackLayout HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
<SwipeView>
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem Text="Favorite"
IconImageSource="favorite.png"
BackgroundColor="LightGreen"
Invoked="Favorite_Invoked" />
@jfversluis
jfversluis / MainPage.xaml
Created December 16, 2019 14:54
SwipeView in Action
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SwipeViewSample.MainPage">
<StackLayout HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
<SwipeView>
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem Text="Favorite"
IconImageSource="favorite.png"
BackgroundColor="LightGreen"
Invoked="Favorite_Invoked" />
@jfversluis
jfversluis / App.xaml.cs
Created December 16, 2019 14:43
Enable the flag
using Xamarin.Forms;
namespace SwipeViewSample
{
public partial class App : Application
{
public App()
{
InitializeComponent();