【问题标题】:How to add a decimal to a sub section (list item \ paragraph) in XAML?如何在 XAML 中的子部分(列表项 \ 段落)中添加小数?
【发布时间】:2021-12-27 11:52:13
【问题描述】:

我正在尝试在 XAML 中创建一个分层编号列表,其中内部列表的编号包含父编号。 即

  1. 一些文字

    1.1 子列表项

    1.2 子列表项

    1.3 子列表项

但我找不到如何做到这一点。我能得到的最好的是单独编号的列表:

  1. 一些文字
    1. 子列表项
    2. 子列表项
    3. 子列表项

the desired outcome

这就是现在的样子: only 1. appears and not 1.1

这是 XAML 代码(我想要 1.1,其中显示“此处为随机文本”):

    <List MarkerStyle="Decimal">
                    <ListItem>
                        <Paragraph FontWeight="Bold" Margin="0,8,0,8">
                            <Span>
                                <Run>Definitions</Run>
                            </Span>
                        </Paragraph>
                        <List MarkerStyle="Decimal">
                            <ListItem Margin="15,0,0,0">
                                <Paragraph Margin="0,8,0,8">
                                    <Span>
                                        <Run>“</Run>
                                    </Span>
                                    <Span FontWeight="Bold">
                                        <Run>Bug Fix</Run>
                                    </Span>
                                    <Span>
                                        <Run>” "Random text here".</Run>
                                    </Span>
                                </Paragraph>
                           </ListItem>
                       </List>

red arrow points to where the 1.1 should be

【问题讨论】:

    标签: c# xaml


    【解决方案1】:

    据我所知,您使用MarkerStyle 尝试这样做是不可能的。这种方式只能嵌套List,你说这不是你想要的。

    在我看来,最好的办法是伪造标记(MarkerStyle 设置为 None 并且标记包含在文本中):

     <List MarkerStyle="None">
        <ListItem>
            <Paragraph FontWeight="Bold" Margin="0,8,0,8">
                <Span>
                    <Run>1. Definitions</Run>
                </Span>
            </Paragraph>
            <List MarkerStyle="None">
                <ListItem Margin="15,0,0,0">
                    <Paragraph Margin="0,8,0,8">
                        <Span>
                            <Run>“</Run>
                        </Span>
                        <Span FontWeight="Bold">
                            <Run>Bug Fix</Run>
                        </Span>
                        <Span>
                            <Run>”1.1 "Random text here".</Run>
                        </Span>
                    </Paragraph>
               </ListItem>
           </List>
        </ListItem>
    </List>
    

    这在 XAML 中很难看,但在 C# 中可能更漂亮(填充 List 时自动编号项目),即:

    // Autonumber concats "i.j" (or "i." if j is null) and "cxyc" 
    l.ListItems.Add(new ListItem(new Paragraph(new Span(new Run(AutoNumber("cxyc",i,j))))));
    

    【讨论】:

    • OK tnx 我现在看到我不能为此使用 MarkerStyle。我会尝试在每个 LI 中添加一个表来实现我想要的
    猜你喜欢
    • 1970-01-01
    • 2021-01-31
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    相关资源
    最近更新 更多