2011-03-11 79 views
1

我有一個的ItemsSource指向一個靜態變量的列表框,併爲ListBox的ItemTemplate一個DataTemplate應顯示變量的說明財產的ItemsSource點WPF列表框的ItemsSource用的DataTemplate

<ListBox x:Name="classificationTypeListBox" 
    ItemsSource="{x:Static h:AmbientHighlightingStyleRegistry.Instance}" 
    SelectedIndex="0" Foreground="Black"> 
    <ListBox.ItemTemplate> 
    <DataTemplate> 
     <TextBlock Text="{Binding Path=(Description)}" /> 
    </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

我可以在我的應用程序中放置一個斷點並查看ListBox。 ItemsSource指向我想要的變量,它看起來像ListBox試圖顯示所有的值,因爲我可以點擊並向下滾動它。但是,沒有文字顯示出來,所以你實際上不知道你點擊了什麼。此外,雖然斷點處於打開狀態,但它表示列表框中包含0項,也許應該是因爲我要綁定它,不確定。有什麼建議麼?

回答

4
<TextBlock Text="{Binding Path=(Description)}" /> 

爲什麼你在那裏有parens?此語法會導致WPF嘗試bind to an attached property,這不是您想要執行的操作。

相關問題