2009-05-15 16 views
12

Come si crea un databound, elenco puntato di collegamenti ipertestuali in WPF?WPF Databound Bulleted List

ho questo:

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

Ma io non riesco a capire come trasformare gli articoli nel proiettili. Vedo BulletDecorator, ma non voglio specificare la mia immagine bullet, voglio solo proiettili standard.

risposta

27

Purtroppo non ci sono "proiettili standard" ... Ecco un esempio di un semplice proiettile Ellisse:

 <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

Giusto per estendere la risposta di @Thomas Levesque un po ', farne un UserControl in modo da poter riutilizzare esso, per esempio:

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

Creare un controllo utente:

<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> 

Nel codice:

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

Per tutti i tipi di elenco è possibile utilizzare il FlowDocument e l'Elenco. Questo ha un MarkerStyle di "Disc" e uno di "Circle".

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

Non ci sono ulteriori dettagli qui: https://msdn.microsoft.com/library/aa970909(v=vs.100).aspx

Problemi correlati