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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:31:36+00:00 2026-06-04T07:31:36+00:00

From the book WPF 4 Unleashed: Although the source property can be any .NET

  • 0

From the book WPF 4 Unleashed:

Although the source property can be any .NET property on any .NET
object, the same is not true for the data-binding target. The target
property must be a dependency property. Also note that the source
member must be a real (and public) property, not just a simple field.

However, here’s a counter example to the claim that the source must be a property. This program binds a Label and a ListBox to a normal field of type ObservableCollection<int>.

Xaml:

<Window x:Class="BindingObservableCollectionCountLabel.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">

    <DockPanel>

        <StackPanel>
            <TextBox Name="textBox" Text="10"/>
            <Button Name="add" Click="add_Click" Content="Add"/>
            <Button Name="del" Click="del_Click" Content="Del"/>
            <Label Name="label" Content="{Binding Source={StaticResource ints}, Path=Count}"/>
            <ListBox ItemsSource="{Binding Source={StaticResource ints}}"/>
        </StackPanel>

    </DockPanel>
</Window>

C#:

using System;
using System.Windows;
using System.Collections.ObjectModel;

namespace BindingObservableCollectionCountLabel
{
    public partial class MainWindow : Window
    {
        public ObservableCollection<int> ints;

        public MainWindow()
        {
            Resources.Add("ints", ints = new ObservableCollection<int>());

            InitializeComponent();
        }

        private void add_Click(object sender, RoutedEventArgs e)
        {
            ints.Add(Convert.ToInt32(textBox.Text));
        }

        private void del_Click(object sender, RoutedEventArgs e)
        {
            if (ints.Count > 0) ints.RemoveAt(0);
        }
    }    
}

So what’s the official word on what qualifies as a data binding source? Should we only bind to properties? Or are fields technically allowed as well?

  • 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-04T07:31:38+00:00Added an answer on June 4, 2026 at 7:31 am

    No, this doesn’t bind to the field esplicitly, it binds to the field, by using a static resource:

    Binding Source={StaticResource ints //StaticResource !!
    

    You can define a static resource whatever you want (basically) and bind to it. If you want to bind directly to your class, you need to use properties as documentation suggests.

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

Sidebar

Related Questions

The book is WPF Unleashed, and it tells that binary resources from a different
From book Java Concurrency in Practice page 26: You can use volatile variables only
I get this code from a book but i could not get it work.
This is based on the example from the book: Pro WPF and Silverlight MVVM
I am wondering why I can't compile an example from book. I simplify the
In a title Forcing a Garbage Colection from book C# 2010 and the .NET
From the book Groovy and Grails recipes I'm using the following code snippet: String
From the book Agile Web Development With Rails class Order < ActiveRecord::Base named_scope :last_n_days,
From a book A common convention is to use .inc for all include files.
Excerpt from a book: A float value consists of a 24-bit signed mantissa 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.