【问题标题】:In monotouch.dialog can RootElement be easily styled?在 monotouch.dialog 中可以轻松设置 RootElement 样式吗?
【发布时间】:2011-08-27 08:35:56
【问题描述】:

是否有任何现有的扩展,或者在 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)
                        }
                    }}
            };

感谢任何帮助或指点。

【问题讨论】:

    标签: xamarin.ios monotouch.dialog


    【解决方案1】:

    这个问题很老,但是如果其他人遇到它,您可以将 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;
            }   
        }
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 感谢您的回答,我只是想知道在编写我自己的之前是否已经存在任何东西,但是因为根元素可以很容易地放置在其他部分等中,并且在这些情况下它们已经具有默认显示,我只是想更改此默认显示。现在我分别创建每个子元素并使用触摸事件根据需要显示它们,而不是让 monotouch.dialog 自动为我完成这一切。有一天我可能会考虑做我最初想做的事情:)
      • 根元素需要设置样式 - 例如,当根元素用于定义子根时更改附件视图。
      猜你喜欢
      • 2011-12-22
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      相关资源
      最近更新 更多