This is a migrated thread and some comments may be shown as answers.

WillSelectItem for TKSideDrawerDelegate?

3 Answers 45 Views
SideDrawer - Xamarin.iOS
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 24 Aug 2016, 01:48 PM
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!

3 Answers, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 29 Aug 2016, 08:09 AM
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
0
Michael
Top achievements
Rank 1
answered on 29 Aug 2016, 03:16 PM
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
0
Adrian
Telerik team
answered on 01 Sep 2016, 01:00 PM
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
Tags
SideDrawer - Xamarin.iOS
Asked by
Michael
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Michael
Top achievements
Rank 1
Share this question
or