【问题标题】:ControlTemplate TextBlock StyleControlTemplate 文本块样式
【发布时间】:2017-02-06 22:17:09
【问题描述】:

当我有 TextBlock 时。 Run Text = "(" Run Text={Binding IncomeLoss} Run Text=")" in a Page 它看起来不错, 但是当我在 ControlTemplate 中有相同的东西应用于从 Control 派生的类时,每个字符之后都会有额外的空格,例如“( 100 ) ”。

我读到 ControlTemplate 是样式继承的障碍,但我如何猜测页面上的 Textblock 通常继承的缺少的样式参数到底是什么?

【问题讨论】:

    标签: wpf xaml templates


    【解决方案1】:

    确保您已将所有Run 元素放在ControlTemplate 中的同一行。

    这两者在输出上有区别:

    <TextBlock><Run Text = "(" /><Run Text="{Binding IncomeLoss}"/><Run Text=")"/></TextBlock>
    

    ...还有这个:

    <TextBlock>
        <Run Text = "(" />
        <Run Text="{Binding IncomeLoss}"/>
        <Run Text=")"/>
    </TextBlock>
    

    如果这不起作用,您应该提供一个最小、完整且可验证的问题示例:https://stackoverflow.com/help/mcve

    【讨论】:

    • 就是这样。如果您能简单地详细说明一下为什么会这样,并且……这是一种在没有 120 列 600 DPI 显示器和 8 倍数的老花镜的情况下保持我的标记井井有条的好方法。
    • 空白字符(空格、换行、制表符)转换为空格:stackoverflow.com/questions/11090084/…
    猜你喜欢
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多