I have an add movie window:
private void button1_Click(object sender, RoutedEventArgs e)
{
string name = txtName.Text;
string genre = txtGenre.Text;
bool dubbed = checkBox1.IsChecked.Value;
bool is3d = checkBox2.IsChecked.Value;
MessageBox.Show(name + " " + genre);
var main = new MainWindow();
main.CallbackAddMovie(name, genre, dubbed, is3d);
this.Close();
}
And the callback:
public class DataItem
{
public string name { get; set; }
public string genre { get; set; }
public bool dubbed { get; set; }
public bool is3d { get; set; }
}
public void CallbackAddMovie(string mname, string mgenre, bool mdubbed, bool mis3d)
{
dataGrid1.Items.Add(new DataItem { name = "Movie name2", genre = "Action", dubbed = true, is3d = true });
dataGrid1.Items.Add(new DataItem { name = mname, genre = mgenre, dubbed = mdubbed, is3d = mis3d });
dataGrid1.SelectAll();
}
When I add a movie, I get the message boxes but the datagrid won't have the new items in it. What is worng?
EDIT:
Here is my datagrid creation:
var colname = new DataGridTextColumn();
colname.Header = "Name";
colname.Binding = new Binding("name");
dataGrid1.Columns.Add(colname);
var colgenre = new DataGridTextColumn();
colgenre.Header = "Genre";
colgenre.Binding = new Binding("genre");
dataGrid1.Columns.Add(colgenre);
var coldubbed = new DataGridCheckBoxColumn();
coldubbed.Header = "Dubbed";
coldubbed.Binding = new Binding("dubbed");
dataGrid1.Columns.Add(coldubbed);
var col3d = new DataGridCheckBoxColumn();
col3d.Header = "3D";
col3d.IsReadOnly = true;
col3d.Binding = new Binding("is3d");
dataGrid1.Columns.Add(col3d);
// create and add two lines of fake data to be displayed, here
dataGrid1.Items.Add(new DataItem { name = "Movie name", genre = "Action", dubbed = true, is3d = true });
EDIT:
Full project:
MainWindow.cs:
http://pastebin.com/Xrr6DjuH
MainWindow.xaml:
http://pastebin.com/SJS4akU4
AddMovie:
http://pastebin.com/J7C5ub8N