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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:15:56+00:00 2026-06-14T06:15:56+00:00

I am struggling to bind a DataGrid to an ObservableCollection in SIlverlight. My very

  • 0

I am struggling to bind a DataGrid to an ObservableCollection in SIlverlight.

My very simple code is below. It currently shows a blank DataGrid. I have gone through tutorials etc and I am sure I am missing something very very basic.

Main Page XAML

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="Tower.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot">
    <sdk:DataGrid Grid.Row="1" Margin="10" IsReadOnly="True" ColumnWidth="120" ItemsSource="{Binding Path=Tests, Mode=OneWay}" AllowDrop="True" />
</Grid>

Main Page Code Behind:

public partial class MainPage : UserControl
{
    public ObservableCollection<Test> Tests { get; set; }

    public MainPage()
    {
        InitializeComponent();

        DataContext = this;

        Tests = new ObservableCollection<Test>();
        Tests.Add(new Test() { Label = "Test1" });
        Tests.Add(new Test() { Label = "Test2" });
        Tests.Add(new Test() { Label = "Test3" });
        Tests.Add(new Test() { Label = "Test4" });
    }
}

Test Class:

public class Test : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged; 

    private String _Label;

    public String Label
    {
        get
        {
            return _Label;
        }
        set
        {
            _Label = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("Label"));
        }
    } 
}
  • 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-14T06:15:57+00:00Added an answer on June 14, 2026 at 6:15 am

    There are two issues in your code –

    • You can only bind with property and not with fields. so make Test property first.
    • Second, you need to set the DataContext to self for binding to work.

      public partial class MainPage : UserControl
      {
         public ObservableCollection<Test> Tests { get; set; }
      
         public MainPage()
         {
             InitializeComponent();
      
             DataContext = this;
      
             Tests = new ObservableCollection<Test>();
             Tests.Add(new Test() { Label = "Test1" });
             Tests.Add(new Test() { Label = "Test2" });
             Tests.Add(new Test() { Label = "Test3" });
             Tests.Add(new Test() { Label = "Test4" });
         }
      }
      

    XAML –

    <Grid x:Name="LayoutRoot">
        <sdk:DataGrid Grid.Row="1" Margin="10" IsReadOnly="True" ColumnWidth="120"
                  ItemsSource="{Binding DataContext.Tests,
                    RelativeSource={RelativeSource FindAncestor,
                     AncestorType= UserControl}}" AllowDrop="True" />
    </Grid>
    

    Notice propertyName – It should be Tests and not tests. This is just a side-note, follow the naming conventions of Microsoft. Property name’s first letter should be uppercase always.

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

Sidebar

Related Questions

this is most likely very easy but i'm struggling $(window).bind(load resize, function(){ var wH
I'm struggling to get the below piece of code working. The problem is that
I'm kind of struggling trying to get this datagrid to bind. Everytime I run
I've been struggling through my first Backbone app and have started to get the
Struggling with styling the mouse over for a button ... I have managed to
Im struggling with this one. I have a list of items and on a
Iam struggling with NHibernate and its lazyload. I have a structure which I simplified
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising
been struggling with an issue now for a day or two. I have an

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.