开发者

WPF ListBox ItemsSource with DataTemplate

I have a ListBox with an ItemsSource pointing to a static variable, and a DataTemplate for the ListBox's ItemTemplate that should be displaying the Description property of the variable the ItemsSource points to

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

I can put a break point on my application and view the ListBox. The ItemsSource does point to the variable I want and it looks like the ListBox is trying to display all the values because I can click and scroll down the it. However, no text is getting displayed so you can't actually tell what you're clicking. Also, while the br开发者_如何学JAVAeak point is on, it says that the list box contains 0 items, maybe it should because I'm binding it, not sure. Any suggestions?


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

Why do you have parens in there? This syntax causes WPF to try to bind to an attached property, which is not what you want to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜