如何在WPF中创建数据绑定,项目符号的超链接列表?
我有这个:
<ItemsControl Name="lstScripts">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink>
<TextBlock Text="{Binding Path=Name}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
但我无法弄清楚如何将物品变成子弹。我看到BulletDecorator,但我不想指定我自己的子弹图像,我只想要标准的子弹。
答案 0 :(得分:29)
不幸的是,没有“标准子弹”......这是一个简单的Ellipse子弹的例子:
<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>
答案 1 :(得分:1)
只是为了扩展@Thomas Levesque的答案,将它变成UserControl,以便你可以重复使用它,例如:
<Reporting:BulletedItem BulletText="Bullet Item 1" />
<Reporting:BulletedItem BulletText="Bullet Item 2" />
创建UserControl:
<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;
}
}
答案 2 :(得分:1)
对于各种列表,您可以使用FlowDocument和List。这有MarkerStyle&#34; Disc&#34;和#34; Circle之一。&#34;
<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