Q:

Datagrid not showing data in wpf with c#

I am trying to use a dataGrid in WPF with c#. But I cannot get my datagrid to show any of my data in the table when I run my program in debug mode. I have this code executing when the datagrid loads. But all I see is an empty square.
private void dataGrid1_Loaded(object sender, RoutedEventArgs e)
{
    var items = new List<SaveTable>();

    items.Add(new SaveTable("A" , 0));
    items.Add(new SaveTable("B" , 0));
    items.Add(new SaveTable("C" , 0));
    items.Add(new SaveTable("D" , 0));
    items.Add(new SaveTable("E" , 0));

    var grid = sender as DataGrid;
    grid.ItemsSource = items;    
}

I save a class named SaveTable which looks like this:
class SaveTable
{

    public string Name { get; set; }
    public double Value { get; set; }

    public SaveTable(string name, double value)
    {
        this.Name = name;
        this.Value = value;
    }
}

I got this code format online and it seems like everything is right? any suggestions?
here is the xaml code for that window
<Window x:Class="RobustCalculator.Storage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Storage" Height="499" Width="546" Activated="Window_Activated" Loaded="Window_Loaded">
<Grid>
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="textBlock1" Text="A" VerticalAlignment="Top" />
    <TextBox HorizontalAlignment="Left" Margin="24,10,0,306" Name="valueA" Width="120" TextChanged="valueA_TextChanged" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="24,39,0,0" Name="valueB" VerticalAlignment="Top" Width="120" TextChanged="valueB_TextChanged" />
    <TextBlock Height="20" HorizontalAlignment="Left" Margin="10,42,0,0" Name="textBlock2" Text="B" VerticalAlignment="Top" Width="20" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="24,71,0,0" Name="valueC" VerticalAlignment="Top" Width="120" TextChanged="valueC_TextChanged" />
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,72,0,0" Name="textBlock3" Text="C" VerticalAlignment="Top" />
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,101,0,0" Name="textBlock4" Text="D" VerticalAlignment="Top" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="24,98,0,0" Name="valueD" VerticalAlignment="Top" Width="120" TextChanged="valueD_TextChanged" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="24,130,0,0" Name="valueE" VerticalAlignment="Top" Width="120" TextChanged="valueE_TextChanged" />
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="11,131,0,0" Name="textBlock5" Text="E" VerticalAlignment="Top" />
    <DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="235,130,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" SelectionChanged="dataGrid1_SelectionChanged" Loaded="dataGrid1_Loaded" />
</Grid>

I added a breakpoint and the code isn't being executed. I am using the Loaded event, should I be using a different event?

A:

Your code works fine with Loaded event but at the moment you set AutoGenerateColumns="False" and don't define columns. You need to either define columns manually 
<DataGrid AutoGenerateColumns="False" ... Loaded="dataGrid1_Loaded">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
        <DataGridTextColumn Binding="{Binding Value}" Header="Value"/>
    </DataGrid.Columns>
</DataGrid>

or let it auto generate columns
<DataGrid AutoGenerateColumns="True" ... Loaded="dataGrid1_Loaded"/>

