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 459519
In Process

The Archive Base Latest Questions

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

I have a ListBox : <ListBox x:Name=HistogramListBox Grid.Column=1 Margin=8,2,8,0 HorizontalAlignment=Stretch VerticalAlignment=Stretch Template={StaticResource HistogramListBoxControlTemplate} ItemContainerStyle={StaticResource

  • 0

I have a ListBox:

<ListBox x:Name="HistogramListBox" Grid.Column="1" Margin="8,2,8,0"
         HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
         Template="{StaticResource HistogramListBoxControlTemplate}"
         ItemContainerStyle="{StaticResource HistogramListBoxItem}"
         ItemTemplate="{DynamicResource BucketTemplate}" />

That uses a DataTemplate that in turn uses a ValueConverter to determine the height of the ListBoxItem:

<DataTemplate x:Key="BucketTemplate">
    <StackPanel>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="100"/>
            </Grid.RowDefinitions>
            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
                <Rectangle Grid.Row="0" StrokeThickness="1" VerticalAlignment="Bottom" 
                           Stroke="{Binding ElementName=MainElement, Path=BucketStroke}" 
                           Fill="{Binding ElementName=MainElement, Path=BucketFill}" >
                    <Rectangle.Height>
                        <MultiBinding Converter="{StaticResource HistogramValueToPercentageConverter}">
                            <Binding Mode="OneWay" Path="ItemCount" />
                            <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:Histogram}}" />
                        </MultiBinding>
                    </Rectangle.Height>
                </Rectangle>
            </StackPanel>
        </Grid>
    </StackPanel>
</DataTemplate>

The ListBox ItemsSource is an int[].

When I execute the code it says it can’t find ‘ItemCount’ on an Int32. I thought it got the item count from the ListBox (I’m obviously wrong).

Can someone tell me how I can get my ValueConverter to know what item I am on.

Thanks

Dan

  • 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-12T22:46:52+00:00Added an answer on May 12, 2026 at 10:46 pm

    Assuming your first converter parameter is intended to be the actual value being charted and the second the Histogram object:

    <Rectangle.Height>
      <MultiBinding Converter="{StaticResource HistogramValueToPercentageConverter}">
        <Binding />
        <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:Histogram}}" />
      </MultiBinding>
    </Rectangle.Height>
    

    This is because the DataContext is the integer itself, at least that appears to be the case from the error message you gave.

    By the way, you would normally set the ListBox’s ItemsSource using a binding, not from code-behind. This leads to much cleaner separation of UI and code. I noticed no ItemsSource= was shown in your example code so I thought I should mention this.

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

Sidebar

Related Questions

I have the following XAML: ... <ListBox Name =RoomsListBox Height=100 HorizontalAlignment=Left Margin=12,41,0,0 VerticalAlignment=Top Width=120></ListBox>
I have a ListBox bound to an ObservableCollection: <ListBox Name=ListBoxItemsList> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin=0
I have listbox that displays information about list of objects: <ListBox Grid.Column=0 Height=152 Name=CustomersList
I have a ListBox in WPF application as : <ListBox HorizontalAlignment=Left Margin=16,37,0,16 Name=lbEmpList Width=194
I have listbox in my wp7 app like this <ListBox Name=lstSelectedNumber Height=50 MaxHeight=120 VerticalAlignment=Top
I have a listbox on a page: <select id=user_list name=user_list size=21 style=width:200px;> <option value=1>User
I have a ListBox showing data about employees such as name, department photo, badge
I have a ListBox simplified to the following XAML <ListBox ItemsSource={Binding Properties} DisplayMemberPath=Name SelectedItem=SelectedProperty
I have the following ListBox with an ItemTemplate <ListBox SelectionMode=Multiple ItemsSource={Binding MyItems} DisplayMemberPath=Name> <ListBox.ItemTemplate>
I'm using WPF and for example I have listbox of professions (Name, Holiday Date,

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.