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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:56:12+00:00 2026-05-28T04:56:12+00:00

What is a DataContext in C#? Are DataContext a kind of new version of

  • 0

What is a DataContext in C#? Are DataContext a kind of new version of DataSource?

  • 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-28T04:56:12+00:00Added an answer on May 28, 2026 at 4:56 am

    (It sounds you mean the FrameworkElement.DataContext property that appears in WPF. If not, oops.)

    It’s somewhat similar to DataSource, but is much more flexible. In WPF, a DataContext can be literally any object that has properties. To bind to a property, you just specify its name and WPF takes care of the rest for you by fishing the specified property out of the DataContext with some reflection magic. (Fields are not supported.)

    For example, if you’re binding a view (say, a UserControl or Window) to an Employee object:

    class Employee {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        // more stuff. . .
    }
    

    then you just set its DataContext to that object. Then the XAML for displaying information from that Employee object could be as simple as:

    <Label Content="{Binding FirstName}"/>
    <Label Content="{Binding LastName}"/>
    

    Optionally, the DataContext can provide additional functionality that allows for richer binding. For example:

    • If it implements INotifyPropertyChanged or has dependency properties, changes to the DataContext will be automatically reflected in the UI.

    • Properties that have setters support two-way binding.

    • If it implements INotifyDataErrorInfo then you can do form validation.

    • If it’s an ADO.NET object, you get all the usual ADO.NET binding magic.

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

Sidebar

Related Questions

The C# code is: DataContext db = new DataContext(MyProject.Properties.Settings.Default.MyString) I am trying to convert
using (var dataContext = new realtydbEntities()) { var user = ( from aspnet_Roles rol
Given: using (DataContext ctx = new DataContext(props.ConnectionString)) { IQueryable<Email> emails = null; try {
Ok... I'm new to WPF, but I kind of know how to do things
Duplicate of : Why are DataContext and ItemsSource not redundant? In WPF we can
Would creating another datacontext in the GetData3() method lead to problems? public void SetoFDataMethods()
I have a custom DataContext with a Table member... Entry is defined as... [Table(Name=Entry)]
When using DataContext.CreateDatabase() to create a database, I wish to stop Linq To Sql
For example a = datacontext.customers.FirstOrDefaul(); b = datacontext.customers.Skip(1).FirstOrDefaul(); a.name=name1; b.Name=name2; When i call datacontext.SubmitChanges(),
I want the datacontext of my listview to be binded to an observable collection.

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.