1

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

基本上我想向 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)
                        }
                    }}
            };

感谢您的任何帮助或指点。

4

2 回答 2

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;
        }   
    }
于 2012-09-12T19:10:05.430 回答
1

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

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

于 2011-05-26T15:39:19.323 回答