ItemCount
属于group在从该Tag生成的集合视图内。
例如如果我有一个列表
AABBBC
而且我组他们我得到:
A组:ItemCount中= 2
B组:ItemCount中= 3
C组: ItemCount = 1
标签云的整个要点是绑定到那个属性,因为你想要显示某个标签被使用的频率。
为了回应您的意见,裸骨设置应该是这样的:
<ItemsControl ItemsSource="{Binding Data}">
<ItemsControl.Resources>
<vc:CountToFontSizeConverter x:Key="CountToFontSizeConverter"/>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Margin="2"
FontSize="{Binding Count, Converter={StaticResource CountToFontSizeConverter}}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我假设你的数据对象类公开属性Name
和Count
,以确保随着数量的增加,数据对象类需要实现INotifyPropertyChanged
这个大小就会随着数量的增加而变化,这就是大约所有的要求。
public class Tag : INotifyPropertyChanged
{
private string _name = null;
public string Name
{
get { return _name; }
set
{
if (_name != value)
{
_name = value;
OnPropertyChanged("Name");
}
}
}
private int _count = 0;
public int Count
{
get { return _count; }
set
{
if (_count != value)
{
_count = value;
OnPropertyChanged("Count");
}
}
}
//...
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
是的,但我已经有我的数据,我无法数数。我所拥有的更像是一个string-int类型的键值列表,我想用一个标签云来显示带有FontSize字符串的int值。 – user579674 2011-05-01 12:49:40
然后你完全没有使用该实现。你可以把它放到一个ItemsControl中并对其进行模板化。那么,至少你不需要重写转换器,但是所有的分组魔法都是毫无意义的。 – 2011-05-01 12:52:32
也许这是真的。有了您的建议,标签云仍然能够随列表更改而动态更新?你能解释一下怎么做吗? – user579674 2011-05-01 12:57:18