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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:50:07+00:00 2026-06-16T07:50:07+00:00

I’m trying to fill a datagrid in WPF the same way I would fill

  • 0

I’m trying to fill a datagrid in WPF the same way I would fill it in Silverlight, but apparently it doesn’t really work the same way.

This is the Grid in XAML:

 <DataGrid x:Name="gvEintraege"
                            CanUserAddRows="False"
                            CanUserDeleteRows="False"
                  IsReadOnly="True"
                  AutoGenerateColumns="True" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="Datum"
                                    Width="100"
                                Binding="{Binding datum}"/>
                <DataGridTextColumn Header="Gewicht"
                                    Width="70"
                                Binding="{Binding gewicht}"/>
                <DataGridTextColumn Header="Muskelmasse"
                                    Width="80"
                                Binding="{Binding muskelmasse}"/>
                <DataGridTextColumn Header="Fettmasse"
                                    Width="70"
                                Binding="{Binding fettmasse}"/>
                <DataGridTextColumn Header="BMI"
                                    Width="40"
                                Binding="{Binding bmi}"/>
                <DataGridTextColumn Header="FFMI"
                                    Width="50"
                                Binding="{Binding ffmi}"/>
                <DataGridTextColumn Header="KFA"
                                    Width="50"
                                Binding="{Binding kfa}"/>
            </DataGrid.Columns></DataGrid>

And this is the entire codebehind:

Public Class LogWindow

Dim gvEintraege_Itemssource As New ObservableCollection(Of clsGridEintrag)
Public globaleVariablen As Application

Public Sub New()

    InitializeComponent()

    Me.globaleVariablen = Application.Current

    Me.getLogEintraege()

    Me.gvEintraege.ItemsSource = Me.gvEintraege_Itemssource
End Sub

Private Sub getLogEintraege()
    Try
        Dim myLog As clsLog = clsSerializer.DeSerialize(Me.globaleVariablen.standardPfadLogs & "\" & Me.globaleVariablen.aktiverUser & ".xml", New clsLog)
        With myLog
            For Each x In .eintraege
                Me.gvEintraege_Itemssource.Add(New clsGridEintrag(x.datum, x.gewicht, x.kfa, x.muskelmasse, x.fettmasse, x.ffmi, x.bmi))
            Next
        End With
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub


Public Class clsGridEintrag
    Public datum As Date
    Public gewicht As Decimal
    Public kfa As Decimal
    Public muskelmasse As Decimal
    Public fettmasse As Decimal
    Public ffmi As Decimal
    Public bmi As Decimal

    Public Sub New()

    End Sub

    Public Sub New(datum_ As Date, gewicht_ As Decimal, kfa_ As Decimal, muskelmasse_ As Decimal, fettmasse_ As Decimal, ffmi_ As Decimal, bmi_ As Decimal)
        Me.bmi = bmi_
        Me.datum = datum_
        Me.fettmasse = fettmasse_
        Me.ffmi = ffmi_
        Me.gewicht = gewicht_
        Me.kfa = kfa_
        Me.muskelmasse = muskelmasse_
    End Sub
End Class

End Class

The grid creates a row for every item in the itemssource, but it doesn’t show any data in the columns. It looks like it should work this way, but apparently I’ve made a mistake somewhere. I’m pulling my hair out over this because it seems so easy, yet it won’t work.

  • 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-16T07:50:09+00:00Added an answer on June 16, 2026 at 7:50 am

    I think you aren’t seeing anything because you’re not using public properties or dependency properties. Binding only works on one of those 2. Since you are trying to bind to public variables, it won’t work. I’m pretty sure the debug output will also warn you that the bindings cannot be found.

    Otherwise, with “Autogenerate Columns” set to true, you don’t have to specify the columns. The grid should be able to read your object (bind it to an observablecollection containing your custom objects) and generate one column for each public dependency property or public property (which means they have get/set accessors).

    And the next answer is right as well, you forgot to set the datacontext 😉

    1. Make sure the DataContext is set.
    2. Create an ObservableCollection as a public property in the window/control class: Public Property myCollection As New ObservableCollection<clsGridEintrag>()
    3. Change your clsGridEintrag variables into “Public Property”, similar to the observablecollection.
    4. Bind your DataGrid’s ItemsSource to myCollection
    5. Populate the ObservableCollection by adding your clsGridEintrag objects one after the other (using myCollection.Add(myObject)).

    I’m not on my coding computer, but the above should give you the results you want if you’re using AutogenerateColumns = true. The DataGrid will name each header after the name of each public property in your clsEntraig object and should list them correctly.

    Here’s some additional information, remember that “Customers” is probably an ObservableCollection that contains “Customer” objects. In the “Customer” objects, the variables we want to see in the DataGrid are most likely set as “Public Property” (in C#, the equivalent is something like public string myString {get; set;} – if you see get/set, it’s a property). Good luck!

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.