c# - DetailText LineBreakMode 不起作用

标签 c# xamarin.ios monotouch.dialog

我有自己的自定义元素,源自 StyledMultilineElement:

public class SubmenuElement : StyledMultilineElement
{

    public static UITableViewCellStyle DefaultCellStyle { get; set; }

    public static UITableViewCellAccessory DefaultCellAccessory { get; set; }
    public static UILineBreakMode DefaultDetailTextLineBreakMode { get; set; }

    public UILineBreakMode DetailTextLineBreakMode { get; set; }
    public int? DetailLines { get; set; }
    public bool? DetailTextResizesFontToFitWidth { get; set; }


    static SubmenuElement()
    {
        // Set the defaults
        DefaultCellStyle = UITableViewCellStyle.Default;
        DefaultCellAccessory = UITableViewCellAccessory.DisclosureIndicator;
        DefaultDetailTextLineBreakMode = UILineBreakMode.TailTruncation;
    }

    ...


    public override UITableViewCell GetCell (UITableView tv)
    {
        var cell = base.GetCell (tv);
        if (cell.DetailTextLabel != null && !string.IsNullOrWhiteSpace(cell.DetailTextLabel.Text))
        {
            if (DetailLines.HasValue)
                cell.DetailTextLabel.Lines = DetailLines.Value;
            cell.DetailTextLabel.LineBreakMode = DetailTextLineBreakMode;
            if (DetailTextResizesFontToFitWidth.HasValue)
                cell.DetailTextLabel.AdjustsFontSizeToFitWidth = DetailTextResizesFontToFitWidth.Value;
        }
        return cell;
    }

}

看来设置DetailText的LineBreakMode没有效果。

public class PeopleView
{

    ....



    void CreateUI()
    {
        var root = new RootElement(Header)
        {
            GroupAndSortResults(people, CurrentState.PeopleDirectoryOptions.GroupAndSort)
                .Select (g => new Section(g.Key)
                {
                    g.Select<PeopleListItem, SubmenuElement> (p => new SubmenuElement(
                        GetName (p),
                        p.TypeGradeSchool, 
                        () => GoToPersonProfile(p.ID),
                        null,
                        UITableViewCellAccessory.None,
                        UITableViewCellStyle.Subtitle
                    )
                {
                    ImageUri = PersonAvatarImage.GetAvatar (p.ID),
                    OnImageLoaded = WhenImageLoaded,
                    DetailTextLineBreakMode = UILineBreakMode.MiddleTruncation,
                    DetailTextResizesFontToFitWidth = true,
                    DetailLines = 0
                }).ToArray ()
                }).ToArray()
        };
        this.Root = root;
        this.NavigationItem.RightBarButtonItems = new UIBarButtonItem[] 
        {
            new UIBarButtonItem(UIBarButtonSystemItem.Organize, new EventHandler(WhenOrganizerTapped)),
            new UIBarButtonItem(UIBarButtonSystemItem.Refresh, new EventHandler(WhenRefreshTapped))
        };
    }

}

关于为什么细节行的截断不起作用有什么想法吗?其他一切正常。我的默认设置是尾部截断,但对于这个特定 View ,我想要中间截断。没有截断样式有效。

最佳答案

我很快就想出来了...当 DetailLines 属性设置为 1 时,它将截断。除非行数设置为 1,否则使用 AdjustsFontSizeToFitWidth 进行截断或文本大小调整不起作用。

如果 SO 上有与此类似的问题,我将删除此问题,除非它被投票(它可以帮助其他人)。

关于c# - DetailText LineBreakMode 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10501487/

相关文章:

ios - 在 Monotouch.Dialog 中录制来自麦克风的声音

ios - Monotouch.Dialog IOS 6 Split View旋转问题

c# - 使用 Adaptive Cards Designer,然后用 C# 中的真实值替换示例值

iphone - Monotouch.Dialog - 设置后退按钮

c# - 获取进程的所有 DLLS

ios - 在 mac 中启动 iOS 模拟器失败

xamarin.ios - MonoTouch 和 Xcode 4

visual-studio - 嵌入图像未在 Xamarin.Forms 中显示

c# - 标签属性的值消失

c# - Xamarin 不兼容的目标框架错误 - NuGet 可以帮助我吗?