I am fairly new to WPF so forgive me if I am missing something obvious. I’m having a problem where I have a collection of AggregatedLabels and I am trying to bind the ItemCount of each AggregatedLabel to the FontSize in my DataTemplate so that if the ItemCount of an AggregatedLabel is large then a larger fontSize will be displayed in my listBox etc. The part that I am struggling with is the binding to the ValueConverter. Can anyone assist? Many thanks!
XAML Snippet
<DataTemplate x:Key="TagsTemplate">
<WrapPanel>
<TextBlock Text="{Binding Name, Mode=Default}"
TextWrapping="Wrap"
FontSize="{Binding ItemCount,
Converter={StaticResource CountToFontSizeConverter},
Mode=Default}"
Foreground="#FF0D0AF7"/>
</WrapPanel>
</DataTemplate>
<ListBox x:Name="tagsList"
ItemsSource="{Binding AggregatedLabels, Mode=Default}"
ItemTemplate="{StaticResource TagsTemplate}"
Style="{StaticResource tagsStyle}"
Margin="200,10,16.171,11.88" />
With your
CollectionViewin place you might be able to bind to theGroupsproperty, i’ve never used that, will try it and clarify if possible…Edit: Allright, here’s one way to do it:
The data you bind to needs to be the
CollectionView.Groups, theCollectionViewshould be defined like this:Then you can bind to the respective properties of
CollectionViewGroupin code, what you need are probably:ItemCountNameThat being said your original binding should work.
Note: You only pass one value to the converter, the ItemCount, thus it should look like this:
Edit: Further clarifications…
Just add the
CollectionViewto yourViewModelas a property and create it in its constructor:Then bind to
AggregatedLabelsView.Groups.