WPF ListBox ItemsSource 与 DataTemplate
我有一个 ListBox,其中 ItemsSource 指向静态变量,以及 ListBox 的 ItemTemplate 的 DataTemplate,该 DataTemplate 应该显示 ItemsSource 指向的变量的 Description 属性
<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 个项目,也许应该是这样,因为我正在绑定它,不确定。有什么建议吗?
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 break point is on, it says that the list box contains 0 items, maybe it should because I'm binding it, not sure. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你那里有父母?此语法会导致 WPF 尝试绑定到附加属性,这不是您想要做的。
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.