在WPF中构建标签云
我正在尝试基于 现有实现 [下载源代码] 。我不完全理解实现,我的问题是,我不想将 FontSize 绑定到集合中的项目数,而是想将其绑定到类中包含的其他一些值。因此,在这一部分中,
FontSize="{Binding Path=ItemCount, Converter={StaticResource CountToFontSizeConverter}}"
我想将 FontSize 绑定到其他内容。我该怎么做? ItemCount 属于哪里?
谢谢
I'm trying to build a tag cloud in WPF based on an existing implementation [Download Source]. I didn't understand completely the implementation and my problem is, that instead of having the FontSize binded to the number of items in a collection, I want to bind it to some other values contained in a class. So in this part here,
FontSize="{Binding Path=ItemCount, Converter={StaticResource CountToFontSizeConverter}}"
I want to bind the FontSize to something else. How do I do that? Where does ItemCount belong to?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ItemCount
属于 group 在从该标签生成的集合视图中。例如,如果我有一个清单
我将它们分组,得到:
标签云的全部意义在于绑定到该属性,因为您希望可视化某个标签的使用频率。
为了回应您的评论,基本设置应该是这样的:
我假设您的数据对象类公开属性
Name
和Count
,以确保随着数据对象类需要实现INotifyPropertyChanged
,这就是它的全部内容。ItemCount
belongs to the group inside the collection view that is generated from that Tag.e.g. if i have a list
And i group them i get:
The whole point of a Tag-Cloud is to bind to that very property because you want to visualize how often a certain tag is used.
To respond to your comments, the bare-bones setup should be something like this:
I assume that your data-object class exposes the properties
Name
andCount
, to make sure that the size changes as count goes up that data-object class needs to implementINotifyPropertyChanged
, that is about all there is to it.ItemCount 是要更改其 FontSize 的 WPF 对象的 DataContext 属性中包含的任何实例的属性。在层次结构树中,从
FrameworkElement
开始的所有内容都继承“DataContext”属性。使用 "snoop",您可以在运行时查看 WPF 应用程序的 UI 树,例如找出哪些对象处于活动状态在任何给定时间都在您的 DataContext 中。
ItemCount is a property of whatever instance is contained in the DataContext property of the WPF object you want to change the FontSize of. In the hierarchy tree, everything from
FrameworkElement
onwards inherits the "DataContext" property.With "snoop" you can look into the UI tree of a WPF App at runtime and e.g. figure out what objects live in your DataContext at any given time.