简体   繁体   中英

Where to set BackgroundColor of Monotouch.Dialog Element?

I am extending the StyledMultilineElement class to make a combination of RadioElement and StyledMultilineElement. The selection and combination of the two are working fine, however I my GetCell override seems to not properly set the background color of the cell.

public override UITableViewCell GetCell (UITableView tv)
    {
        var cell = base.GetCell (tv);

        bool selected = RadioIdx == this.rgroup.Selected;
        cell.Accessory = selected ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None;
        cell.BackgroundColor = selected ? UIColor.Cyan : UIColor.White;
        return cell;
    }

The checkmark does appear on the selected element telling me that the selected boolean is indeed correct, however the background color always appears as white.

I am assuming this is just because I am trying to do it in the GetCell method, but I'm not sure where else to put it.

So the question is, where would I set the BackgroundColor since it obviously isn't working here?

Have you tried setting the BackgroundColor property of the actual Element itself?

There are a few properties:

  • UITableViewCellAccessory Accessory
  • int Lines
  • UILineBreakMode LineBreakMode
  • UIColor TextColor
  • UIFont SubtitleFont
  • UIFont Font

These seem to be the area for setting the style.

Also, if the value of selected changes, the cell won't actually update right away. What you can do as well to refresh the cell is to call this when you want to refresh the cell:

RootElement root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);

The GetImmediateRootElement() method is on the actual element.

references: MonoTouch.Dialog: Update of Text in an Element

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM