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

  • Home
  • SEARCH
  • 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 8832359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:30:41+00:00 2026-06-14T08:30:41+00:00

I learn bindings in WPF via book. I have wrote such code: using System;

  • 0

I learn bindings in WPF via book. I have wrote such code:

using System;

namespace WpfBinding {
    enum SomeColors {
        Red,
        Green,
        Blue,
        Gray
    }
}

and

using System;

namespace WpfBinding {
    class TestItem {
        SomeColors color;

        public TestItem(SomeColors color) {
            Color = color;
        }
        internal SomeColors Color {
            get { return color; }
            set { color = value; }
        }
        public override string ToString() {
            return Color.ToString();
        }
    }
}

XAML of my Window:

<Window x:Class="WpfBinding.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">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ListBox x:Name="listBox" HorizontalAlignment="Stretch" 
                 VerticalAlignment="Stretch" Margin="5"/>
        <ComboBox x:Name="comboBox" HorizontalAlignment="Stretch" 
                  VerticalAlignment="Top" Margin="5" Grid.Column="1"/>
    </Grid>
</Window>

I have tried create binding through code:

using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfBinding {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            // Data for listbox
            TestItem[] items = new TestItem[] {
                new TestItem(SomeColors.Red), 
                new TestItem(SomeColors.Green), 
                new TestItem(SomeColors.Green), 
                new TestItem(SomeColors.Red), 
                new TestItem(SomeColors.Blue), 
                new TestItem(SomeColors.Red), 
            };
            // Create ObservableCollection item
            ObservableCollection<TestItem> collection = new ObservableCollection<TestItem>(items);
            listBox.ItemsSource = collection;// set data for listbox

            comboBox.ItemsSource = Enum.GetValues(typeof(SomeColors)); // Get items from my enum

            // Create bindings
            Binding bind = new Binding();
            bind.Source = listBox;
            bind.Path = new PropertyPath("SelectedItem.Color");
            bind.Mode = BindingMode.TwoWay;
           comboBox.SetBinding(ComboBox.SelectedItemProperty, bind);
        }
    }
}

But my binding ain’t working. Why?

Screen:
enter image description here

  • 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-06-14T08:30:42+00:00Added an answer on June 14, 2026 at 8:30 am

    Here is the error –

    System.Windows.Data Error: 40 : BindingExpression path error: 'Color' property
    not found on 'object' ''TestItem' (HashCode=13974362)'.  
    BindingExpression:Path=SelectedItem.Color; DataItem='ListBox' (Name='listBox');
    target element is 'ComboBox' (Name='comboBox'); target property is 'SelectedItem'
    (type 'Object')
    

    You need to make the property Color public instead of internal.

    From MSDN here –

    The properties you use as binding source properties for a binding must
    be public properties of your class. Explicitly defined interface
    properties cannot be accessed for binding purposes, nor can protected,
    private, internal, or virtual properties that have no base
    implementation.

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

Sidebar

Related Questions

As an exercise to learn wpf and understand how binding works I have an
I have been trying to learn and take advantage of WPF and databinding. I
I have an application I am creating in WPF, using MVVM pattern. In this
I'm relatively new to OOD, C#, WPF, but trying to learn. So I have
When I see people using MySQL, it's generally via the PHP bindings. Is it
We have an EPOS system that is built in VB6. A client is using
I have recently start to learn WPF + MVVM. It is possible I have
I'm trying to learn emacs, getting vi custom key bindings. Using Viper-mode, what is
Starting to learn Canvas and have two classes so far (main one to call
I am trying to learn MySQL select statements a little better and I have

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.