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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:05:55+00:00 2026-05-23T12:05:55+00:00

Folks, I’m having an interesting issue with Silverlight DataGrid data binding. It may be

  • 0

Folks,

I’m having an interesting issue with Silverlight DataGrid data binding. It may be b/c I’m not binding the data source properly. Here’s the object & the observable collection

/// <summary>
/// Interface for all model elements
/// </summary>
public interface IBaseModel
{

}


/// <summary>
/// Employee model
/// </summary>
public class EmployeeModel : IBaseModel
{       

    public string FirstName { get; set; }
    public string LastName { get; set; }

    public override string ToString()
    {
        return FirstName + LastName;
    }
}


// The observable collection is loaded and bound in the user control
public partial class EmployeeMasterDetailsWindow : UserControl
{
    public EmployeeMasterDetailsWindow()
    {

        try
        {
            InitializeComponent();
            ObservableCollection<IBaseModel> k = new ObservableCollection<IBaseModel>() 
                {new EmployeeModel(){FirstName="Frodo", 
                               LastName=" Baggins"}, 
                new EmployeeModel(){FirstName="Pippin", 
                               LastName="Thomas"}, 
                new EmployeeModel(){FirstName="John", 
                               LastName="Doe"}, 
                new EmployeeModel(){FirstName="Tim", 
                               LastName="Kiriev"}}; 

            dataGrid1.DataContext = k;
            CustomersListBox.DataContext = k;

        }
        catch (Exception ex)
        {


        }

    }
}



//here's the XAML
<UserControl x:Class="AdventureWorksManagement.UI.EmployeeMasterDetailsWindow"
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="379" d:DesignWidth="516"
         xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
         xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">


<UserControl.Resources>       

    <DataTemplate x:Key="CustomerTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding FirstName}" />
            <TextBlock Text=" " />
            <TextBlock Text="{Binding LastName}" />
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="White" Height="371" Width="595">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="312*" />
        <ColumnDefinition Width="283*" />
    </Grid.ColumnDefinitions>

    <sdk:DataGrid Height="325" HorizontalAlignment="Left"
                  Margin="12,12,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="271" ItemsSource="{Binding}"
                  RowDetailsTemplate="{StaticResource CustomerTemplate}">

    </sdk:DataGrid>
           <ListBox x:Name="CustomersListBox"
             Margin="10,10,10,11"
             ItemsSource="{Binding}"
             ItemTemplate="{StaticResource CustomerTemplate}" />
</Grid>

The Listbox shows all the of the employees, but the DataGrid doesn’t. I don’t even see the DataGrid. I see this error message in the output window:

‘System.Collections.ObjectModel.ObservableCollection1[AdventureWorksManagement.Model.IBaseModel]'
'System.Collections.ObjectModel.ObservableCollection
1[AdventureWorksManagement.Model.IBaseModel]’
(HashCode=54025633).
BindingExpression: Path=’FirstName’
DataItem=’System.Collections.ObjectModel.ObservableCollection`1[AdventureWorksManagement.Model.IBaseModel]’
(HashCode=54025633); target element is
‘System.Windows.Controls.TextBlock’
(Name=”); target property is ‘Text’
(type ‘System.String’)..

What could I be doing wrong?

  • 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-23T12:05:55+00:00Added an answer on May 23, 2026 at 12:05 pm

    By making it an ObservableCollection<IBaseModel> you are effectively casting all the child objects to IBaseModel, which has no members.

    In this instance make it an ObservableCollection<EmployeeModel>.

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

Sidebar

Related Questions

Folks, why jQuery hover does not work? Here is the link - http://layot.prestatrend.com/ Thanks
Folks, I'm tryning to extract data from web page using C#.. for the moment
Folks, I have just joined this company which has a huge source tree based
Folks, here's a thorny problem for you! A part of the TickZoom system must
Folks, My Issue Why is an HSQLDB file-based database I have pre-populated with a
Folks, I'm using i nternal:merge tool since I'm not a big fan of GUI
folks, i got an issue which really pain for me i got few line
Folks, I've got a strange issue at the moment with a visual studio 2010
Folks, here is the situation: confirmed that the xlsx file is good on the
folks, here ma code : #include <glib.h> #include <gio/gio.h> // gio channel #include <sys/socket.h>

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.