Skip to content

Instantly share code, notes, and snippets.

@shanempope
Last active March 21, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanempope/ee585de7c943ae3ecfc4 to your computer and use it in GitHub Desktop.
Save shanempope/ee585de7c943ae3ecfc4 to your computer and use it in GitHub Desktop.
Some iOS listview effects for xamarin
using Xamarin.Forms;
[assembly: ResolutionGroupName ("MyCompany")]
[assembly: ExportEffect (typeof (NotScrollableListviewEffect), "NotScrollableListviewEffect")]
[assembly: ExportEffect (typeof (NoDividerListviewEffect), "NoDividerListviewEffect")]
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()));
}
}
}
}
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()));
}
}
}
}
@shanempope
Copy link
Author

In your PCL page you'll want to add this after initialize component
_listView.Effects.Add(Effect.Resolve("MyCompany.NoDividerListviewEffect"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment