Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

shanempope commented Mar 21, 2016

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
You can’t perform that action at this time.