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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:34:11+00:00 2026-06-04T03:34:11+00:00

Background I’m trying to bind my objects to a DataGrid I have a list

  • 0

Background

I’m trying to bind my objects to a DataGrid

I have a list of PhoneVM objects. Each item in the list contains a list of StringBindingData. I need each item in StringBindingData to correspond to a different cell in a row of a DataGrid

Each item int he list corresponds to a different value for a user’s configuration, including Description and Value.

PhoneVM is defined as:

public class PhoneVM 
{
    public List<StringBindingData> StringBindingData { get; private set; }

    public PhoneVM()
    {

    }
}

and StringBindingData is defined as:

public class StringBindingData : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public string Description { get; set; }

    private string _value;
    public string Value
    {
        get { return _value; }
        set
        {
            OnPropertyChanged("Value");
        }

    }

    public StringBindingData(string data, string description)
    {
        Value = data;
        Description = description;
    }

    internal void OnPropertyChanged(string prop)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(prop));
        }
    }
}

The Description property of the first item in the StringBindingData list might contain “Name” and the Value property would contain the actual name. The Description property of the second item in the list might contain “Phone Number” and the Value property would contain the actual number.

Question

I want to get these to bind to a DataGrid. How can I do this?

What I have so far is an attempt to bind the first column to the Name

<DataGrid Name="phoneGrid" AutoGenerateColumns="False" Height="150" Width="Auto" 
            SelectionMode="Single" SelectionUnit="FullRow" Margin="10,10,0,0" 
            HorizontalAlignment="Left" VerticalAlignment="Top" SelectionChanged="phoneGrid_SelectionChanged">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name"
            x:Name="columnPhoneNumber" 
            Binding="{Binding Path=Value}"
            IsReadOnly="True">
        </DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

With this in the code behind:

public Phone(List<PhoneVM> phoneVm)
{
    InitializeComponent();

    phoneGrid.DataContext = phoneVm;
}

But even looking at the code it’s obviously wrong. I don’t know how to specify for the DataContext that I want it to get the StringBindingData objects from phoneVm and take the data from that.

Is there something I need to add to the XAML to get this working? Is there something else I can add to the code? Do I need to change my data model?

  • 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-04T03:34:12+00:00Added an answer on June 4, 2026 at 3:34 am

    As you say, you’re missing the binding to the StringBindingData property in your view model. Try adding ItemsSource="{Binding StringBindingData}" to your DataGrid.

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

Sidebar

Related Questions

Background I have a dimension table that has a single record for each day.
Background I have a secured folder containing secret report files (in pdf format). Each
Background I am trying to create a copy of a business object I have
Background, Part 1 I have a form that collects both frequency and duration from
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
Background I have an existing extension designed to accompany a browser-based game (The extension
Background We need to develop a specialised CMS (internal use only) to support a
Background: I have a css and a js that is used only by the
Background: Sometimes when editing in vim it is possible to have extra characters in
Background I have a ror application which is continuously recording and showing on 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.