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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:36:44+00:00 2026-05-24T05:36:44+00:00

I am trying to bind a Silverlight Datagrid to an ObservableCollection<T> . Specifically I

  • 0

I am trying to bind a Silverlight Datagrid to an ObservableCollection<T>.

Specifically I have ObservableCollection<Target> where target has the following properties: Hierarchy and Item.

I only want the datagrid to display information for the Hierarchy class but when the user selects a row I want both the Hierarchy and the item properties of the Target class to be available in code.

Is this possible?

Thanks.

  • 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-24T05:36:45+00:00Added an answer on May 24, 2026 at 5:36 am

    Specify paths for the Hierarchy properties in your columns like this:

    Binding="{Binding Hierarchy.Title}"
    

    Full example below:

    MainPage.xaml

    <UserControl x:Class="GridBinding.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" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
    
        <Grid x:Name="LayoutRoot" Background="White">
            <sdk:DataGrid ItemsSource="{Binding Targets}" AutoGenerateColumns="False" Name="dataGrid1" SelectionChanged="dataGrid1_SelectionChanged">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Header="Title" Binding="{Binding Hierarchy.Title}" Width="Auto" />
                    <sdk:DataGridTextColumn Header="Text" Binding="{Binding Hierarchy.Text}" Width="Auto" />
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
        </Grid>
    </UserControl>
    

    MainPage.cs

    using System.Collections.ObjectModel;
    using System.Windows.Controls;
    
    namespace GridBinding
    {
        public partial class MainPage : UserControl
        {
            public ObservableCollection<Target> Targets { get; set; }
    
            public MainPage()
            {
                InitializeComponent();
                this.Targets = new ObservableCollection<Target>()
                                {
                                    new Target(){ Hierarchy = new Hierarchy(){Text = "Text 1", Title = "Title 1"}, Item = new Item(){Name = "Name 1"}},
                                    new Target(){ Hierarchy = new Hierarchy(){Text = "Text 2", Title = "Title 2"}, Item = new Item(){Name = "Name 2"}},
                                    new Target(){ Hierarchy = new Hierarchy(){Text = "Text 3", Title = "Title 3"}, Item = new Item(){Name = "Name 2"}},
                                };
                this.DataContext = this;
            }
    
            private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                DataGrid dataGrid = sender as DataGrid;
                Target target = dataGrid.SelectedItem as Target;
                Hierarchy heirarchy = target.Hierarchy;
                Item item = target.Item;
            }
        }
    
        public class Target
        {
            public Hierarchy Hierarchy { get; set; }
            public Item Item { get; set; }
        }
    
        public class Hierarchy
        {
            public string Title { get; set; }
            public string Text { get; set; }
        }
    
        public class Item
        {
            public string Name { get; set; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to bind a Silverlight DataGrid to the results of a WCF service
I have a ASP.net gridview that I am trying bind to. My DataSource has
Im trying to bind a list with datetime objects to my repeater. if (e.Item.ItemType
I'm trying to bind the following shortcut: Ctrl + W to close tabs How
I'm trying to bind my view to my view model without DataObjectProvider. The following
I'm having a heck of a time trying to get a silverlight datagrid to
I am trying to use databinding to bind data to a Silverlight toolkit chart.
I'm trying to override the default DatePicker template in Silverlight. I want to remove
I am trying to bind a listview item to a member of a structure,
Using Silverlight 4 / MVVM. I am trying to bind a ViewModel to a

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.