WillSelectItem for TKSideDrawerDelegate?

4 posts, 0 answers
  1. Michael
    Michael avatar
    7 posts
    Member since:
    Jun 2016

    Posted 24 Aug Link to this post

    Hello,

    Just curious if there's anyway to use an override for a selection color (when the user is tapping - before the action is completed so like a TouchesBegan)? I'd like t set a color as a highlight but I don't see a way to do this in the API docs or the getting started docs (or while browsing the assembly in Xamarin Studio). Is there a way to do this out of the box? Or, if not, is there a way to do this using something like TouchesBegan? I've tried to override TouchesBegan but it doesn't seem to work in the TKSideDrawerDelegate class.

    Thank you!
  2. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 29 Aug Link to this post

    Hello, Michael,

    Thank you for writing.
    This scenario can be achieved by subclassing TKSideDrawerTableViewCell and overriding its SetSelected() method. You can use this method to change the cell's item stroke and fill colors when the cell is selected. Consider the code below:
    class Cell : TKSideDrawerTableViewCell
            {
                public override void SetSelected(bool selected, bool animated)
                {
                    base.SetSelected(selected, animated);
                    if (selected)
                    {
                        this.Item.Style.Fill = new TKSolidFill(UIColor.Red);
                    }
                    else {
                        this.Item.Style.Fill = new TKSolidFill(UIColor.Clear);
                    }
                }
            }

     Then you should use TKSideDrawerDelegate's method CellForItem() to create a cell:
    public override TKSideDrawerTableViewCell CellForItem(TKSideDrawer sideDrawer, NSIndexPath indexPath)
    {
        Cell c = new Cell();
        TKSideDrawerSection section = sideDrawer.Sections[indexPath.Section];
        c.Item = section.Items[indexPath.Item];
        return c;
    }

    I hope this helps.

    Regards,
    Adrian
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Michael
    Michael avatar
    7 posts
    Member since:
    Jun 2016

    Posted 29 Aug in reply to Adrian Link to this post

    Thank you for the response but this seems to change the color after tapping the item. This would be fine but is there a way to reset the color next time the side drawer is opened? Additionally, is there a way to show the color when the user is holding an item (but has not yet selected it)?

    Thanks!
    Michael
  5. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 01 Sep Link to this post

    Hello, Michael,

    Yes, the scenario you described can be easily achieved by overriding the cell's SetHighlighted() instead of SetSelected(). You can use the same code as shown in my previous response:
    public override void SetHighlighted(bool highlighted, bool animated)
                {
                    base.SetHighlighted(highlighted, animated);
                    if (highlighted)
                    {
                        this.Item.Style.Fill = new TKSolidFill(UIColor.Red);
                    }
                    else {
                        this.Item.Style.Fill = new TKSolidFill(UIColor.Clear);
                    }
                    this.SetNeedsDisplay();
                }

    I hope this helps.

    Regards,
    Adrian
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner