如何在 wpf 中的文本绑定前添加项目符号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26258450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:35:55  来源:igfitidea点击:

How do I add a bullet point in front of a text binding in wpf?

c#wpfxamldecorator

提问by Lunyx

I have the following abbreviated for simplicity

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

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

How can I get it so that my TextBox shows a bullet point in front of the text bound to it? Desired format:

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

  • List item 1
  • List item 2
  • 列出项目 1
  • 列出项目 2

回答by Sajeetharan

You can use the BulletDecoratorwith the TextBlock. Example:

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

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