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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:45:35+00:00 2026-05-29T17:45:35+00:00

I have a class Student with 3 attributes (first name, last name, age). In

  • 0

I have a class Student with 3 attributes (first name, last name, age).

In .xaml ( basically two rectangles – each containing 3 text blocks bind to those 3 attributes).

<Border  Grid.Column="0" Grid.Row="5" >
        <StackPanel Orientation="Horizontal">
                <Rectangle Width="16" Height="16" Name="rectangle1" />
                <TextBlock Text="{Binding Mode=TwoWay, Path=FirstName}"  Padding="2"/>
                <TextBlock Text="{Binding Mode=TwoWay, Path=LastName}" Padding="2"/>
                <TextBlock Text="{Binding Mode=TwoWay, Path=Age}" Padding="2"/>
        </StackPanel>
    </Border>
    <Border  Grid.Column="0" Grid.Row="6">
        <StackPanel Orientation="Horizontal">
            <Rectangle Width="16" Height="16"  Fill="{Binding Converter={StaticResource AvailabilityToBrushConverter1}, Path=IsAvailable}" Name="rectangle2"/>
            <TextBlock Text="{Binding Mode=TwoWay, Path=FirstName}"  Padding="2"/>
            <TextBlock Text="{Binding Mode=TwoWay, Path=LastName}" Padding="2"/>
            <TextBlock Text="{Binding Mode=TwoWay, Path=Age}" Padding="2"/>
        </StackPanel>
    </Border>

In .xaml.cs

Student student1 = new Student { FirstName = "James", LastName = "Peter", Age= 12 ,IsAvailable=true  };
Student student2 = new Student { FirstName = "Mark", LastName = "Smith", Age = 20 };

after InitializeComponent

InitializeComponent();     
DataContext = student1;

When i run i get

James Peter 12
James Peter 12

I want on form load

James Peter 12
Mark Smith 20

I tried to use this, but didn’t work:

rectangle1.DataContext=student1;
rectangle2.DataContext=student2;

How do i set two different values for these 2 rectangles?

  • 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-29T17:45:37+00:00Added an answer on May 29, 2026 at 5:45 pm

    The Rectangles do not contain the TextBlocks, in both cases a StackPanel does, you should set the DataContext on them instead.

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

Sidebar

Related Questions

I have two student objects. class Student{ int physics; int english; int chemistry; }
I have two scaffold-generated Models, student and class . They have a many-to-many relationship
I have two entities which are Student and Class entities. Student and Class are
If I have these 3 classes: class Student { int id; string name; }
I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit
Let's assume we have a class Student with the following constructor: /** Initializes a
I have a Personnel class, where I store all of Objects of type student,
I have 3 tables in my SQL Server database: Teacher Student Parent Each of
I have such terrible models: class ParentalRelation < ActiveRecord::Base belongs_to :parent belongs_to :student belongs_to
Alright, so this is the exercise: Define a class named student, containing three grades

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.