Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3876764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:25:12+00:00 2026-05-19T22:25:12+00:00

I am fairly new to WPF so forgive me if I am missing something

  • 0

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" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:25:12+00:00Added an answer on May 19, 2026 at 10:25 pm

    With your CollectionView in place you might be able to bind to the Groups property, 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, the CollectionView should be defined like this:

    CollectionView view = (ListCollectionView) CollectionViewSource.
        GetDefaultView(LabelData);
    view.GroupDescriptions.Add(new PropertyGroupDescription("Name"));
    

    Then you can bind to the respective properties of CollectionViewGroup in code, what you need are probably:

    1. ItemCount
    2. Name

    That being said your original binding should work.

    Note: You only pass one value to the converter, the ItemCount, thus it should look like this:

    public class CountToFontSizeConverter : IValueConverter
    {
        #region IValueConverter Members
    
        public object Convert(object value, Type targetType, object parameter, 
            CultureInfo culture)
        {
            const int minFontSize = 6;
            const int maxFontSize = 38;
            const int increment = 3;
    
            if ((minFontSize + (int)value + increment) < maxFontSize)
            {
                return (double)(minFontSize + (int)value + increment);
            }
            return (double)maxFontSize;
        }
    
        public object ConvertBack(object value, Type targetType, 
            object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

    Edit: Further clarifications…

    Just add the CollectionView to your ViewModel as a property and create it in its constructor:

    public class TagCloudViewModel//:INotifyPropertyChanged
    {
        public ObservableCollection<AggregatedLabelModel> AggregatedLabels 
            {get; set;}
        public CollectionView AggregatedLabelsView {get; set;} // <-This...
    
        public TagCloudViewModel()
        {
            var data = new DataAccess();
            AggregatedLabels = data.GetData();
    
            //...and this:
            AggregatedLabelsView  = (ListCollectionView)CollectionViewSource.
                GetDefaultView(AggregatedLabels);
            AggregatedLabelsView.GroupDescriptions.Add(
                new PropertyGroupDescription("Name"));
        }
    }
    

    Then bind to AggregatedLabelsView.Groups.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to WPF and am probably missing something simple here. If
I am fairly new to WPF and I am having a problem with inheriting
I fairly new to JQuery and perhaps trying to achieve something that might be
I am fairly new to WPF and am having trouble getting the DataTemplateKey to
I'm fairly new to WPF and I have some problems getting databinding to work
Fairly new to wpf, using the galasoft mvvm templates. I have two relaycommands that
I'm fairly new to WPF and have since created applications with Win Forms and
I'm fairly new to WPF and looking for a simple solution to the problem
I'm fairly new to C# and WPF programing and right now this problem is
I am fairly new to WPF but have spent time researching WPF validation, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.