17

如何在 WPF 中创建数据绑定、项目符号的超链接列表?

我有这个:

<ItemsControl Name="lstScripts">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock>
                <Hyperlink>
                    <TextBlock Text="{Binding Path=Name}" />
                </Hyperlink>
            </TextBlock>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

但我不知道如何将这些物品变成子弹。我看到 BulletDecorator,但我不想指定自己的项目符号图像,我只想要标准项目符号。

4

3 回答 3

33

不幸的是,没有“标准项目符号”......这是一个简单的椭圆项目符号的示例:

        <ItemsControl Name="lstScripts">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <BulletDecorator Width="Auto">
                        <BulletDecorator.Bullet>
                            <Ellipse Fill="White" Stroke="Black" StrokeThickness="1" Width="8" Height="8"/>
                        </BulletDecorator.Bullet>
                        <TextBlock>
                            <Hyperlink>
                                <TextBlock Text="{Binding Path=Name}" />
                            </Hyperlink>
                        </TextBlock>
                    </BulletDecorator>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
于 2009-05-15T19:12:40.027 回答
2

只是为了扩展@Thomas Levesque 的答案,将其变成 UserControl 以便您可以重用它,例如:

<Reporting:BulletedItem BulletText="Bullet Item 1" />
<Reporting:BulletedItem BulletText="Bullet Item 2" />

创建一个用户控件:

<UserControl x:Class="MyNameSpace.Reporting.BulletedItem"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" >
    <Grid>
        <ItemsControl >
            <BulletDecorator Width="Auto" Margin="10, 0, 0, 0">
                <BulletDecorator.Bullet>
                    <Ellipse Fill="Black" Stroke="Black" StrokeThickness="1" Width="5" Height="5"/>
                </BulletDecorator.Bullet>
                <TextBlock Margin="5, 0, 0, 0">
                    <TextBlock Text="{Binding BulletText}" />
                </TextBlock>
            </BulletDecorator>
        </ItemsControl>
    </Grid>
</UserControl>

在代码中:

public partial class BulletedItem : UserControl
{
    public static readonly DependencyProperty TextProperty = DependencyProperty.Register("BulletText", typeof(string), typeof(BulletedItem));

    public string BulletText
    {
        get { return (string)GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }

    public BulletedItem()
    {
        InitializeComponent();
        this.DataContext = this;
    }
}
于 2013-10-02T13:54:36.260 回答
2

对于各种列表,您可以使用 FlowDocument 和 List。这具有“Disc”的 MarkerStyle 和“Circle”之一。

<FlowDocument>
  <List MarkerStyle="Disc">
    <ListItem>
      <Paragraph>Boron</Paragraph>
    </ListItem>
    <ListItem>
      <Paragraph>Carbon</Paragraph>
    </ListItem>
</<FlowDocument>

这里有更多详细信息:https ://msdn.microsoft.com/library/aa970909(v=vs.100).aspx

于 2016-01-15T15:02:28.170 回答