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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:37:46+00:00 2026-05-14T00:37:46+00:00

The following XAML produces a run-time Binding error when I click on an item

  • 0

The following XAML produces a run-time Binding error when I click on an item in the ListBox:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication1.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">
    <Window.Resources>
        <x:Array x:Key="strings" Type="{x:Type sys:String}">
            <sys:String>one</sys:String>
            <sys:String>two</sys:String>
            <sys:String>three</sys:String>
            <sys:String>four</sys:String>
        </x:Array>
    </Window.Resources>
    <Grid>
        <ListBox
            DataContext="{StaticResource strings}"
            IsSynchronizedWithCurrentItem="True"
            ItemsSource="{Binding}"
            SelectedValuePath="{Binding /Length}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.Resources>
                            <Style TargetType="{x:Type Label}">
                                <Setter Property="Background" Value="Yellow"/>
                                <Setter Property="Margin" Value="0,0,4,0"/>
                                <Setter Property="Padding" Value="0"/>
                            </Style>
                        </Grid.Resources>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <!-- Row 0 -->
                        <Label Grid.Column="0" Grid.Row="0">String:</Label>
                        <TextBlock
                            Grid.Column="1"
                            Grid.Row="0"
                            Text="{Binding}"/>
                        <!-- Row 1 -->
                        <Label Grid.Column="0" Grid.Row="1">Length:</Label>
                        <TextBlock
                            Grid.Column="1"
                            Grid.Row="1"
                            Text="{Binding Length, Mode=Default}"/>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>

This is the run-time Binding error message:

System.Windows.Data Error: 39 : BindingExpression path error: ‘3’ property not found on ‘object’ ”String’ (HashCode=1191344027)’. BindingExpression:Path=3; DataItem=’String’ (HashCode=1191344027); target element is ‘ListBox’ (Name=”); target property is ‘NoTarget’ (type ‘Object’)

I would like the selected value of the ListBox to be the Length of the selected String object. What is wrong with my SelectedValuePath Binding syntax? Are there any related issues with IsSynchronizedWithCurrentItem?

  • 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-14T00:37:46+00:00Added an answer on May 14, 2026 at 12:37 am

    Short answer

    Replace

    SelectedValuePath="{Binding /Length}"
    

    with

    SelectedValuePath="Length"
    

    Long answer

    SelectedValuePath is a string that gives the path from an object to the selected value. By writing SelectedValuePath="{Binding /Length}" you are binding SelectedValuePath (not SeletedValue) to the “Length” property of the selected item, so if the length of the selected item is 3 then the value of the SelectedValuePath property is set to the string “3”. Then WPF tries to compute SelectedValue by finding a property named “3” on the string. Since the string object doesn’t have a property named “3” you get the error.

    You might think that SelectedValue={Binding /Length}" would do the trick, and indeed it does express the concept of what you are actually trying to do. But it does not actually work because Selector has code that overwrites SelectedValue whenever SelectedItem changes.

    Another way to look at this is that setting SelecteValuePath to the value “abcd” is effectively equivalent to setting SelectedValue to "{Binding /abcd}" (but only if IsSynchronizedWithCurrentItem=”true”).

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

Sidebar

Related Questions

The following xaml code works: <Window x:Class=DerivedTemplateBug.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:DerivedTemplateBug Title=Window1 Height=300 Width=300> <Button>
I've got the following xaml: <Window x:Class=Isolator.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Isolator Height=394 Width=486 Background=Black WindowStyle=None
Suppose the following XAML defined window: <Window x:Class=LayoutTests.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:LayoutTests Title=Window1> <Window.Resources> <XmlDataProvider
Consider following XAML: <Window x:Class=WpfApplication1.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <StackPanel> <TextBlock Text={Binding Dic[foo]}
I have written following xaml code: <Window x:Class=WpfApplication3.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=200 Width=200> <StackPanel>
Consider the following XAML: <Window x:Class=ContextMenuEvent.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525 ContextMenuOpening=Window_ContextMenuOpening> <Grid> <Button>Ok</Button>
I have the following XAML for the main window: <Window x:Class=ImageViewer.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Window1
I have the following XAML: <UserControl x:Class=EMS.Controls.Dictionary.TOCControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:EMS.Controls.Dictionary.Models xmlns:diagnostics=clr-namespace:System.Diagnostics;assembly=WindowsBase x:Name=root > <TreeView
See the following XAML: <UserControl xmlns:sdk=http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk x:Class=SilverlightApplication1.MainPage xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 mc:Ignorable=d d:DesignHeight=300 d:DesignWidth=400
I have the following XAML code: <ListBox ItemsSource={Binding Languages}> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Image Source={Binding

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.