【问题标题】:How do I add a bullet point in front of a text binding in wpf?如何在 wpf 中的文本绑定前添加项目符号?
【发布时间】:2014-12-03 04:55:03
【问题描述】:

为简单起见,我有以下缩写

<ItemsControl ItemSource="{Binding enumerableList}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBox Text="{Binding displayName, Mode=OneWay}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

我怎样才能让我的 TextBox 在绑定到它的文本前面显示一个项目符号?所需格式:

  • 列表项 1
  • 列表项 2

【问题讨论】:

  • 您是否考虑过修改 displayName 属性以在返回之前将项目符号字符添加到值的前面?或者制作一个 ValueConverter 来做到这一点?

标签: c# wpf xaml decorator


【解决方案1】:

您可以将BulletDecorator 与TextBlock 一起使用。示例:

    <BulletDecorator>
      <BulletDecorator.Bullet>
        <Ellipse Height="10" Width="10" Fill="Blue"/>
      </BulletDecorator.Bullet>
        <TextBox Text="{Binding displayName, Mode=OneWay}" />
    </BulletDecorator>

【讨论】:

  • 或者,如果我想切换到数字、字母或罗马数字,是否有类似的东西而不将其添加到我的实际文本字符串中?
猜你喜欢
  • 2010-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-26
  • 1970-01-01
  • 2012-07-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多