2009-05-15 22 views
12

¿Cómo creo una lista de hipervínculos encuadernados y encuadernados en WPF?WPF Lista de viñetas con enlaces de datos

Tengo esto:

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

Pero no puedo encontrar la manera de convertir los elementos en balas. Veo el BulletDecorator, pero no quiero especificar mi propia imagen de viñeta, solo quiero las viñetas estándar.

Respuesta

27

Lamentablemente no hay "balas estándar" ... He aquí un ejemplo de una simple bala Elipse:

 <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

Sólo para extender la respuesta de @Thomas Levesque un poco, lo convierten en un control de usuario para que pueda volver a utilizar que, por ejemplo:

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

Crear un control de usuario:

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

En el código:

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

Para todo tipo de lista, puede utilizar el FlowDocument y la lista. Esto tiene un MarkerStyle de "Disco" y uno de "Círculo".

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

Hay más detalles aquí: https://msdn.microsoft.com/library/aa970909(v=vs.100).aspx

Cuestiones relacionadas