2010-07-21 62 views
1

我試圖創建一個PropertyCollection的DataTemplates(的PropertyDescriptor)以這種格式來顯示集合中的項目,如何創建的DataTemplate與鏈接

descriptor1> descriptor2> descriptor3> descriptor4> descriptor5

每個描述符都將是一個鏈接(使用超鏈接),我的問題是我可以使用Labels(它不是​​ItemsControl主機)嗎?如果是的話,任何人都可以給我一個關於如何使用DataTemplates實現這個功能的例子嗎?

此外,有沒有辦法從DataTemplate訪問屬性描述符?例如,假設我想將當前的屬性描述符實例用作CommandParameter。

感謝任何幫助,謝謝。

回答

1

你可以試着用一個ListBox和一個ItemsPanel來做到這一點,這個ItemsPanel使用項目的水平佈局(我只是綁定到我的例子中的一串字符串)。 HTH。

代碼:

public List<string> Properties { get; set; } 

XAML:

<ListBox ItemsSource="{Binding Properties}"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
          ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}" 
          MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}" 
          ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" /> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 

    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock> 
       <Hyperlink NavigateUri="{Binding}"> 
        <TextBlock Text="{Binding StringFormat={}{0} >}"/> 
       </Hyperlink> 
      </TextBlock> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

截圖:

alt text http://i25.tinypic.com/28hq7h2.png

+0

完美,感謝您的快速反應,它的工作太棒了! – liaaba 2010-07-21 20:45:24