Last active
March 21, 2016 15:52
-
-
Save shanempope/ee585de7c943ae3ecfc4 to your computer and use it in GitHub Desktop.
Some iOS listview effects for xamarin
This file contains 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
~ |
This file contains 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
using Xamarin.Forms; | |
[assembly: ResolutionGroupName ("MyCompany")] | |
[assembly: ExportEffect (typeof (NotScrollableListviewEffect), "NotScrollableListviewEffect")] | |
[assembly: ExportEffect (typeof (NoDividerListviewEffect), "NoDividerListviewEffect")] |
This file contains 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
using System; | |
using Xamarin.Forms.Platform.iOS; | |
using UIKit; | |
namespace MyCompany.Mobile.iOS.Views.Effects | |
{ | |
public class NoDividerListviewEffect : PlatformEffect | |
{ | |
protected override void OnAttached () | |
{ | |
var tableView = Control as UITableView; | |
if (tableView != null) | |
{ | |
tableView.SeparatorStyle = UITableViewCellSeparatorStyle.None; | |
} | |
else | |
{ | |
throw new InvalidOperationException(string.Format("Attaching effect to wrong kind of class. Expected: UITableView Got: {0}", Control.GetType())); | |
} | |
} | |
protected override void OnDetached () | |
{ | |
var tableView = Control as UITableView; | |
if (tableView != null) | |
{ | |
tableView.SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine; | |
} | |
else | |
{ | |
throw new InvalidOperationException(string.Format("Attaching effect to wrong kind of class. Expected: UITableView Got: {0}", Control.GetType())); | |
} | |
} | |
} | |
} | |
This file contains 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
using System; | |
using Xamarin.Forms.Platform.iOS; | |
using UIKit; | |
namespace MyCompany.Mobile.iOS.Views.Effects | |
{ | |
public class NotScrollableListviewEffect : PlatformEffect | |
{ | |
protected override void OnAttached () | |
{ | |
var tableView = Control as UITableView; | |
if (tableView != null) | |
{ | |
tableView.ScrollEnabled = false; | |
} | |
else | |
{ | |
throw new InvalidOperationException(string.Format("Attaching effect to wrong kind of class. Expected: UITableView Got: {0}", Control.GetType())); | |
} | |
} | |
protected override void OnDetached () | |
{ | |
var tableView = Control as UITableView; | |
if (tableView != null) | |
{ | |
tableView.ScrollEnabled = true; | |
} | |
else | |
{ | |
throw new InvalidOperationException(string.Format("Attaching effect to wrong kind of class. Expected: UITableView Got: {0}", Control.GetType())); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your PCL page you'll want to add this after initialize component
_listView.Effects.Add(Effect.Resolve("MyCompany.NoDividerListviewEffect"));