2009-05-15 5 views
12

Comment créer une liste de liens hypertexte à base de puces dans WPF?Liste à puces WPF Databound

J'ai ceci:

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

Mais je ne peux pas comprendre comment transformer les éléments en balles. Je vois le BulletDecorator, mais je ne veux pas spécifier ma propre image de balle, je veux juste des balles standard.

Répondre

27

Malheureusement, il n'y a pas de « balles standard » ... Voici un exemple de simple balle 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

Juste pour prolonger la réponse de @Thomas Levesque un peu, faire un UserControl afin que vous puissiez réutiliser il, par exemple:

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

Créer un 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> 

Dans le 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; 
    } 
} 
0

Pour toutes sortes de listes, vous pouvez utiliser FlowDocument et List. Cela a un MarkerStyle de "Disc" et un de "Circle".

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

Il y a plus de détails ici: https://msdn.microsoft.com/library/aa970909(v=vs.100).aspx

Questions connexes