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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:14:01+00:00 2026-06-18T01:14:01+00:00

Student class public class Student { string name; List<SubjectInfo> subjectInfoList; …. } List<SubjectInfo> List

  • 0

Student class

public class Student
{
    string name;        
    List<SubjectInfo> subjectInfoList;    
    ....
}

List<SubjectInfo> List can have different number of SubjectInfo objects for different students.

SubjectInfo struct

public struct SubjectInfo
{
    string subjectCode;
    int marks;
    ...
}

I want to display student object detail on a window. Since List have different number of object count I used ItemsControl and used dataTemplate.

Binding a student object works perfectly.

Student student = new Student("Joe", new List<SubjectInfo>() { new SubjectInfo("Subject1", 50), new SubjectInfo("Subject2", 70) });  
StudentGrid.DataContext = student;  

But this TwoWay binding is not working for SubjectInfo(Changing value from UI will not caught by the codebehind)
But if change SubjectInfo struct to SubjectInfo class it works.

Cannot understand why. Please advice me.

  • 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-18T01:14:02+00:00Added an answer on June 18, 2026 at 1:14 am

    By assigning a SubjectInfo to DataContext, it is copied (because it is a struct/ValueType), that’s why the binding does not work. This is in most cases not what you want. I suggest you use a class for SubjectInfo instead.

    You should be aware of the differences between class and struct. The C# Specification (V4.0) summarizes them like this (in section 11.3):

    • Structs are value types (§11.3.1).
    • All struct types implicitly inherit from the class System.ValueType (§11.3.2).
    • Assignment to a variable of a struct type creates a copy of the value being assigned (§11.3.3).
    • The default value of a struct is the value produced by setting all value type fields to their default value and all reference type fields to null (§11.3.4).
    • Boxing and unboxing operations are used to convert between a struct type and object (§11.3.5).
    • The meaning of this is different for structs (§7.6.7).
    • Instance field declarations for a struct are not permitted to
      include variable initializers (§11.3.7).
    • A struct is not permitted to declare a parameterless instance constructor (§11.3.8).
    • A struct is not permitted to declare a destructor (§11.3.9).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Student class public class Student { string name; List<SubjectInfo> subjectInfoList; .... } List<SubjectInfo> List
Let's have this code : class student :IComparable , IComparable<student> { public string name
I have class student : public class Student { public string Name { get;
I have a class named Student public class Student { public string Name {
I have an ASP.NET WebService that returns an object of List public class Students
I'm having syntax troubles. public class Student { int StudentId; string Name; } public
Suppose I have a simple model: public class studentNames { string name{get; set;} }
I have these two classes: class Student { String name; String age ; }
I have the code as below. class Student : IPeople { private string name;
I have a custom class student as below: public class Student { public string

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.