2009-05-15 20 views
12

WPF'de nasıl veri gönderilir, madde işaretli bir köprü oluşturur?WPF Databound Madde İşaretli Liste

ben hallederim:

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

Ama kurşunlara içine öğeleri açmak için anlamaya olamaz. BulletDecorator'ı görüyorum ama kendi mermi imgesini belirtmek istemiyorum, sadece standart mermi istiyorum.

cevap

27

Maalesef hayır "standart mermiler" vardır ... İşte basit Elips merminin bir örnek:

 <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

Sadece @Thomas Levesque cevabı biraz uzatmak Yeniden kullanabileceğiniz bu yüzden bir UserControl içine Yapmak o, mesela: kodunda

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

:

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

bir UserControl oluşturun

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

Tüm liste türleri için FlowDocument ve List'ü kullanabilirsiniz. Bu bir "Disk" MarkerStyle ve "Circle" dan biri.

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

daha fazla detay burada vardır: https://msdn.microsoft.com/library/aa970909(v=vs.100).aspx

İlgili konular