Question

Comment puis-je créer une databound, liste à puces de liens hypertextes dans WPF?

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 préciser ma propre image de balle, je veux juste des balles standard.

Était-ce utile?

La solution

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

Autres conseils

Juste pour prolonger la réponse de @Thomas Levesque un peu, faire un UserControl afin que vous puissiez le réutiliser, 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;
    }
}

Pour toutes sortes de liste, vous pouvez utiliser la FlowDocument et la liste. Cela a un MarkerStyle de « disque » et l'un des « Cercle ».

<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 / bibliothèque / aa970909 (v = VS.100) .aspx

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top