Instantly share code, notes, and snippets.
Last active
November 24, 2016 12:41
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save xperseguers/61905abc1b511dd94cd51a4442a4c45c to your computer and use it in GitHub Desktop.
SocialNetworksCell to be used with Xamarin.Forms within a TableView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void InitializeTableView () | |
{ | |
var root = new TableRoot(); | |
var section = new TableSection { | |
Title = "Social" | |
}; | |
var socialNetworks = new SocialNetworksCell (); | |
socialNetworks.SetSocialNetwork("Skype", "xperseguers"); | |
socialNetworks.SetSocialNetwork("Twitter", "xperseguers"; | |
section.Add (socialNetworks); | |
root.Add (section); | |
tableView.Root = root; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Using directives | |
using Xamarin.Forms; | |
using MyProjectUI.ValueConverters; | |
using MyProject; | |
#endregion Using directives | |
namespace MyProjectUI.Controls | |
{ | |
public class SocialNetworksCell : ViewCell | |
{ | |
public static readonly BindableProperty SkypeProperty = | |
BindableProperty.Create ("Skype", typeof(string), typeof(SocialNetworksCell), default(string)); | |
public string Skype { | |
get { return (string)GetValue (SkypeProperty); } | |
set { SetValue (SkypeProperty, value); OnPropertyChanged ("Skype"); } | |
} | |
public static readonly BindableProperty TwitterProperty = | |
BindableProperty.Create ("Twitter", typeof(string), typeof(SocialNetworksCell), default(string)); | |
public string Twitter { | |
get { return (string)GetValue (TwitterProperty); } | |
set { SetValue (TwitterProperty, value); OnPropertyChanged ("Twitter"); } | |
} | |
public static readonly BindableProperty FacebookProperty = | |
BindableProperty.Create ("Facebook", typeof(string), typeof(SocialNetworksCell), default(string)); | |
public string Facebook { | |
get { return (string)GetValue (FacebookProperty); } | |
set { SetValue (FacebookProperty, value); OnPropertyChanged ("Facebook"); } | |
} | |
public static readonly BindableProperty GooglePlusProperty = | |
BindableProperty.Create ("GooglePlus", typeof(string), typeof(SocialNetworksCell), default(string)); | |
public string GooglePlus { | |
get { return (string)GetValue (GooglePlusProperty); } | |
set { SetValue (GooglePlusProperty, value); OnPropertyChanged ("GooglePlus"); } | |
} | |
public static readonly BindableProperty LinkedInProperty = | |
BindableProperty.Create ("LinkedIn", typeof(string), typeof(SocialNetworksCell), default(string)); | |
public string LinkedIn { | |
get { return (string)GetValue (LinkedInProperty); } | |
set { SetValue (LinkedInProperty, value); OnPropertyChanged ("LinkedIn"); } | |
} | |
public static readonly BindableProperty XingProperty = | |
BindableProperty.Create ("Xing", typeof(string), typeof(SocialNetworksCell), default(string)); | |
public string Xing { | |
get { return (string)GetValue (XingProperty); } | |
set { SetValue (XingProperty, value); OnPropertyChanged ("Xing"); } | |
} | |
public static readonly BindableProperty InstagramProperty = | |
BindableProperty.Create ("Instagram", typeof (string), typeof (SocialNetworksCell), default (string)); | |
public string Instagram { | |
get { return (string)GetValue (InstagramProperty); } | |
set { SetValue (InstagramProperty, value); OnPropertyChanged ("Instagram"); } | |
} | |
public static readonly BindableProperty FlickrProperty = | |
BindableProperty.Create ("Flickr", typeof (string), typeof (SocialNetworksCell), default (string)); | |
public string Flickr { | |
get { return (string)GetValue (FlickrProperty); } | |
set { SetValue (FlickrProperty, value); OnPropertyChanged ("Flickr"); } | |
} | |
public static readonly BindableProperty YouTubeProperty = | |
BindableProperty.Create ("YouTube", typeof (string), typeof (SocialNetworksCell), default (string)); | |
public string YouTube { | |
get { return (string)GetValue (YouTubeProperty); } | |
set { SetValue (YouTubeProperty, value); OnPropertyChanged ("YouTube"); } | |
} | |
public static readonly BindableProperty PinterestProperty = | |
BindableProperty.Create ("Pinterest", typeof (string), typeof (SocialNetworksCell), default (string)); | |
public string Pinterest { | |
get { return (string)GetValue (PinterestProperty); } | |
set { SetValue (PinterestProperty, value); OnPropertyChanged ("Pinterest"); } | |
} | |
public SocialNetworksCell () | |
{ | |
var s = new StackLayout { | |
Padding = Styles.ListItemPadding (), | |
Spacing = 19, | |
Orientation = StackOrientation.Horizontal, | |
HorizontalOptions = LayoutOptions.Start | |
}; | |
MessagingCenter.Subscribe<ContentPage> (this, Messages.ORIENTATION_CHANGED, (sender) => s.Padding = Styles.ListItemPadding ()); | |
var skype = new Image { Source = "SocialSkype" }; | |
skype.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "Skype", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var skypeTap = new TapGestureRecognizer (); | |
skypeTap.Tapped += (sender, e) => App.PhoneFeatureService.Skype (Skype); | |
skype.GestureRecognizers.Add (skypeTap); | |
s.Children.Add (skype); | |
var twitter = new Image { Source = "SocialTwitter" }; | |
twitter.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "Twitter", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var twitterTap = new TapGestureRecognizer (); | |
twitterTap.Tapped += (sender, e) => App.PhoneFeatureService.OpenTwitter (Twitter); | |
twitter.GestureRecognizers.Add (twitterTap); | |
s.Children.Add (twitter); | |
var facebook = new Image { Source = "SocialFacebook" }; | |
facebook.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "Facebook", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var facebookTap = new TapGestureRecognizer (); | |
facebookTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (Facebook); | |
facebook.GestureRecognizers.Add (facebookTap); | |
s.Children.Add (facebook); | |
var googlePlus = new Image { Source = "SocialGooglePlus" }; | |
googlePlus.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "GooglePlus", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var googlePlusTap = new TapGestureRecognizer (); | |
googlePlusTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (GooglePlus); | |
googlePlus.GestureRecognizers.Add (googlePlusTap); | |
s.Children.Add (googlePlus); | |
var linkedIn = new Image { Source = "SocialLinkedIn" }; | |
linkedIn.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "LinkedIn", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var linkedInTap = new TapGestureRecognizer (); | |
linkedInTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (LinkedIn); | |
linkedIn.GestureRecognizers.Add (linkedInTap); | |
s.Children.Add (linkedIn); | |
var xing = new Image { Source = "SocialXing" }; | |
xing.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "Xing", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var xingTap = new TapGestureRecognizer (); | |
xingTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (Xing); | |
xing.GestureRecognizers.Add (xingTap); | |
s.Children.Add (xing); | |
var instagram = new Image { Source = "SocialInstagram" }; | |
instagram.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "Instagram", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var instagramTap = new TapGestureRecognizer (); | |
instagramTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (Instagram); | |
instagram.GestureRecognizers.Add (instagramTap); | |
s.Children.Add (instagram); | |
var flickr = new Image { Source = "SocialFlickr" }; | |
flickr.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "Flickr", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var flickrTap = new TapGestureRecognizer (); | |
flickrTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (Flickr); | |
flickr.GestureRecognizers.Add (flickrTap); | |
s.Children.Add (flickr); | |
var youTube = new Image { Source = "SocialYouTube" }; | |
youTube.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "YouTube", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var youTubeTap = new TapGestureRecognizer (); | |
youTubeTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (YouTube); | |
youTube.GestureRecognizers.Add (youTubeTap); | |
s.Children.Add (youTube); | |
var pinterest = new Image { Source = "SocialPinterest" }; | |
pinterest.SetBinding (Image.IsVisibleProperty, new Binding { | |
Source = this, | |
Path = "Pinterest", | |
Converter = new NotEmptyToBooleanConverter () | |
}); | |
var pinterestTap = new TapGestureRecognizer (); | |
pinterestTap.Tapped += (sender, e) => App.PhoneFeatureService.Browse (Pinterest); | |
pinterest.GestureRecognizers.Add (pinterestTap); | |
s.Children.Add (pinterest); | |
this.BindingContext = this; | |
View = new ScrollView { | |
Orientation = ScrollOrientation.Horizontal, | |
Content = s | |
}; | |
} | |
public void SetSocialNetwork (string type, string value) | |
{ | |
switch (type) { | |
case "Skype": | |
Skype = value; | |
break; | |
case "Twitter": | |
Twitter = value; | |
break; | |
case "Facebook": | |
Facebook = value; | |
break; | |
case "Google+": | |
GooglePlus = value; | |
break; | |
case "LinkedIn": | |
LinkedIn = value; | |
break; | |
case "Xing": | |
Xing = value; | |
break; | |
case "Instagram": | |
Instagram = value; | |
break; | |
case "Flickr": | |
Flickr = value; | |
break; | |
case "YouTube": | |
YouTube = value; | |
break; | |
case "Pinterest": | |
Pinterest = value; | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment