Frage
Wie erstelle ich eine Databound, Aufzählungen Liste von Hyperlinks in WPF?
Ich habe diese:
<ItemsControl Name="lstScripts">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink>
<TextBlock Text="{Binding Path=Name}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Aber ich kann nicht herausfinden, wie die Elemente in Kugeln zu drehen. Ich sehe den BulletDecorator, aber ich will nicht meine eigene Kugel Bild angeben, ich will nur Standard-Kugeln.
Lösung
Leider gibt es keine „Standard-Kugeln“ ... Hier ist ein Beispiel für eine einfache Ellipse Kugel:
<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>
Andere Tipps
Just @Thomas Levesque Antwort ein wenig zu verlängern, ist es in einem Usercontrol, so dass Sie es wieder verwenden können, z.
<Reporting:BulletedItem BulletText="Bullet Item 1" />
<Reporting:BulletedItem BulletText="Bullet Item 2" />
Erstellen ein 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>
Im Code:
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;
}
}
Für alle Arten von Liste können Sie den Flowdocument und Liste verwenden. Dies hat eine MarkerStyle von „Disc“ und einem „Kreis.“
<FlowDocument>
<List MarkerStyle="Disc">
<ListItem>
<Paragraph>Boron</Paragraph>
</ListItem>
<ListItem>
<Paragraph>Carbon</Paragraph>
</ListItem>
</<FlowDocument>
Es gibt weitere Details hier: https://msdn.microsoft .com / library / aa970909 (v = VS.100) aspx