在monotouch.dialog中,RootElement可以轻松设置样式吗?

时间:2011-05-17 15:32:04

标签: xamarin.ios monotouch.dialog

是否存在任何现有扩展,或者在monotouch.dialog中向RootElement添加样式是非常简单的,方法与StyledStringElement的样式类似。

基本上我想在RootElement中添加一个图像或徽章,以指示子视图中的详细信息,例如添加成功,警告,错误,信息类型图像 - 这样用户可能只对点击感兴趣到完全没有成功的细节。

理想情况下,我可以编写类似这样的代码......

UIImage imageSuccess = ImageLoader.DefaultRequestImage (new Uri ("file://" + Path.GetFullPath ("Images/Success.png")), null);

var root = new RootElement("Root") {
                Image = imageSuccess,
                Accessory = UITableViewCellAccessory.DetailDisclosureButton,
                new Section (){
                    new BooleanElement ("Airplane Mode", false),
                    new RootElement ("Notifications") {
                        new Section (null, "Turn off Notifications")
                        {
                            new BooleanElement ("Notifications", false)
                        }
                    }}
            };

感谢您提供任何帮助或指示。

2 个答案:

答案 0 :(得分:4)

这个问题很老,但是如果有其他人遇到它,你可以继承RootElement类来添加一个图标。我的代码如下:

    public class ImageRootElement : RootElement
    {
        private UIImage _image;

        public override MonoTouch.UIKit.UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv)
        {
            var baseCell = base.GetCell (tv); 
            var cell = new UITableViewCell (UITableViewCellStyle.Subtitle, "cellId");
            cell.TextLabel.Text = Caption;

            cell.Accessory = baseCell.Accessory;
            cell.ImageView.Image = _image;
            return cell;
        }

        public ImageRootElement (string caption, UIImage image) : base(caption)
        {
            _image = image;
        }   
    }

答案 1 :(得分:1)

由于MT.Dialog是开源的,您可以根据需要修改RootElement属性和构造函数。我认为没有任何东西可以开箱即用,所以你必须扩展Dialog以满足你的需求。

顺便说一下,听起来你可能误解了RootElement的意图。 RootElement只是所有部分和元素所在的主要容器。在RootElement上设置披露指示符或徽章似乎没有意义,因为这不是RootElement的意图。我可能会误解你。但是,如果要在元素上使用徽章等进行自定义样式,则可以创建从OwnerDrawnElement继承的自定义元素类,从而覆盖它的两个抽象方法。但是,在这样做之前,请阅读Miguel对类似问题here的回答。