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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:53:47+00:00 2026-05-31T13:53:47+00:00

I am going through the Sams book Teach Yourself WPF in 24 Hours. At

  • 0

I am going through the Sams book “Teach Yourself WPF in 24 Hours”. At one point the authors show how you can bind a ListBox’s selected-item value to a property. I get that, it’s pretty straightforward. But when I try to create my own ListBox control with my own ListBoxItems, I can’t seem to get it to work.

The ListBox that works uses a system collection as its ItemsSource property:

<ListBox x:Name="FontList"
         DockPanel.Dock="Left"
         ItemsSource="{x:Static Fonts.SystemFontFamilies}"
         Width="160" />

The value selected from this ListBox is then used in a TextBlock as follows:

<TextBlock Text="Test" 
           FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
           TextWrapping="Wrap"
           Margin="0 0 0 4" />

Notice that the Path is set to SelectedItem.

Now, I wanted to set the FontSize using another ListBox that contains 3 different sizes. Here is what I did:

<ListBox x:Name="Size" >
    <ListBoxItem>10</ListBoxItem>
    <ListBoxItem>15</ListBoxItem>
    <ListBoxItem>20</ListBoxItem>
</ListBox>

And then I added a binding to the Size attribute of the TextBox as follows:

<TextBlock Text="Test" 
           FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
           Size="{Binding ElementName=Size, Path=SelectedItem}"
           TextWrapping="Wrap"
           Margin="0 0 0 4" />

The Size doesn’t change when I run the program. So I tried to add the binding I was using for Size to the Text attribute–in order to see its value:

<TextBlock Text="{Binding ElementName=Size, Path=SelectedItem}"" 
           FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
           Size="{Binding ElementName=Size, Path=SelectedItem}"
           TextWrapping="Wrap"
           Margin="0 0 0 4" />

I see that it is changing as I click the Size ListBox, but I also see that the SelectedItem is displaying as this (when I click the 15 entry):
System.Windows.Controls.ListBoxItem:15

My questions:
1) What is the actual value being returned by the Path called SelectedItem? Is it “System.Windows.Controls.ListBoxItem:15” or is it “15”? If it’s not 15, how can I specify a Path that returns just 15 and not System.Windows.Controls.ListBoxItem:15?

2)Why does the FontFamily SelectItem work? I realize that the FontList is coming from a System collection of font names, but it is unclear to me why the ListBox isn’t returning a collection of ListBoxItems as text. If my ListBox’s Path reference is returning a SelectedItem object of type ListBoxItem, then I would think I could use a Path of SelectedItem.Value or something like that–but it doesn’t work and there is no Intellisense to help me.

I want to get THIS example working because it will help clear-up some misunderstandings I have. Please don’t refactor the solution to get it to work some other way unless it’s entirely impossible for me to have a Path reference that will give me just the numeric portion of my Size ListBoxItem that is selected.

  • 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-31T13:53:48+00:00Added an answer on May 31, 2026 at 1:53 pm

    What is the actual value being returned by the Path called SelectedItem?

    It is System.Windows.Controls.ListBoxItem:15 (you can read this as “ListBoxItem with content set to 15”), that’s why your binding does not work – it expects a numeric value, not ListBoxItem. You can specify Path as SelectedItem.Content to make this work. Also you can set SelectedValuePath of ListBox “Size” to “Content”, and bind to SelectedValue property instead of SelectedItem.

    Solution 1:

    <TextBlock Size="{Binding ElementName=Size, Path=SelectedItem.Content}" />
    

    Solution 2:

    <ListBox x:Name="Size" SelectedValuePath="Content" />
    <TextBlock Size="{Binding ElementName=Size, Path=SelectedValue}" />
    

    Why does the FontFamily SelectItem work?

    Because that ListBox contains a font collection, not a collection of ListBoxItems (they are still created to represent each item in a collection though). You can achieve the same behavior with font sizes if you define collection of font sizes in code and bind ListBox’es ItemsSource property to that collection or define contents of your ListBox as a collection of System.Double values directly in XAML:

    <ListBox x:Name="Size"
             xmlns:system="clr-namespace:System;assembly=mscorlib">
        <system:Double>10</system:Double>
        <system:Double>15</system:Double>
        <system:Double>20</system:Double>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am going through a Sams learn Android SDK in 24 hours book
I am very new to iPhone dev and while going through Sams Teach Yourself
While going through a WP7.5 background transfer service policy, one can read the following:
While going through one project, I have seen that the memory data is 8
After going through the Appendix A, C# Coding Style Conventions of the great book
While going through one of the problems in Python Challenge , I am trying
After going through the discussion here I have one more question now. Lets assume,
Going through the Lynda training for Ruby on Rails and got to the point
While going through one of our own projects, that other developer used rand() to
While going through the Intermediate Perl book I noticed a section on Schwartzian Transforms

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.