【问题标题】:How can I add <Run Text="xx"/> to TextBox c#? Or how can I append dynamic string to static string in TextBox?如何将 <Run Text="xx"/> 添加到 TextBox c#?或者如何将动态字符串附加到 TextBox 中的静态字符串?
【发布时间】:2015-10-06 18:28:16
【问题描述】:

在 WPF 中,我知道对于 TextBlock,当我想将一些“动态”字符串附加到字符串时,我可以执行以下操作:

<TextBlock>
    <Run Text ="static string"/>
    <Run Text="{Binding dynamicstring}"/>
</TextBlock>

但是,同样的方法对TextBox不起作用,有没有办法用TextBox做同样的事情

【问题讨论】:

  • 你需要在ControlTemplate of TextBox中定义它
  • 例如检查This
  • @litaoshen 在我看来你应该关注RichTextBox 而不是TextBox
  • @dkozl thx 首先,但目前我在工具箱中找不到 RichTextBox,可能是因为我正在编写一些通用应用程序(这个适用于 WP 8.1)
  • 我们可以适当地安排 2 个具有同质背景的元素来模仿你想要的。当您想要反转某些东西(将静态字符串附加到动态字符串)时,这会更难。在这种情况下,我们需要跟踪插入符号并相应地调整静态字符串元素。

标签: c# xaml textbox windows-phone-8.1 textblock


【解决方案1】:

尝试使用 RichEditBox。

<RichEditBox>
    <Paragraph>
       <Run Text="Static Text" />
       <Run Text="{Binding Dynamic}" />
    </Paragraph>
</RichEditBox>

如果您使用的是 Windows Phone Silverlight

<RichTextBox>
    <Paragraph>
       <Run Text="Static Text" />
       <Run Text="{Binding Dynamic}" />
    </Paragraph>
</RichTextBox>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 2023-01-19
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多