I have 2 classes: Multimedia and MultimediaList and 2 windows: my main window and the input window where I insert my data in order to add new items to the listbox.
my Multimedia class looks like this:
public class Multimedia : INotifyPropertyChanged
{
public enum MediaType
{
CD,
DVD
};
private string _title;
private string _artist;
private string _genre;
private MediaType _type;
public Multimedia(string title, string artist, string genre, MediaType type)
{
_title = title;
_artist = artist;
_genre = genre;
_type = type;
}
public String Title
{
get { return this._title; }
set { this._title = value; }
}
public String Artist
{
get { return this._artist; }
set { this._artist = value; }
}
public String Genre
{
get { return this._genre; }
set { this._genre = value; }
}
public MediaType Type
{
get { return this._type; }
set { this._type = value; }
}
public event PropertyChangedEventHandler PropertyChanged;
}
and this is my MultimediaList class:
public class MultimediaList : ObservableCollection<Multimedia>
{
public MultimediaList()
{
Add(new Multimedia("Blaster", "UFK", "Dubstep", Multimedia.MediaType.CD));
Add(new Multimedia("Hello", "Habstrakt", "Dubstep", Multimedia.MediaType.DVD));
Add(new Multimedia("Black Veil", "Straight Line Stich", "Metal", Multimedia.MediaType.CD));
Add(new Multimedia("Ridiculous", "Dope D.O.D", "Hip-Hop", Multimedia.MediaType.DVD));
}
public void addItem(string title, string artist, string genre, Multimedia.MediaType type)
{
Add(new Multimedia(title, artist, genre, type));
}
}
The listbox is populated with the items that were setup manually in the programme,therefore that works but now I want to use my second window to add items to the listbox.
this is my second window setup:
private MultimediaList myList = new MultimediaList();
public InputWindow()
{
InitializeComponent();
PopulateComboBox();
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
myList.addItem(textBox.Text, textBox1.Text, textBox2.Text, Multimedia.MediaType.CD);
//Close();
}
XML:
<ListBox DisplayMemberPath="Title" Name="listBox1" ...></ListBox>
Whenever I press the save button, the listbox from my main window is not populated with the new data. Can anyone help me with this?
And this is my main window code:
public MainWindow()
{
InitializeComponent();
myList = new MultimediaList();
listBox1.ItemsSource = myList;
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
ModalWindow input = new ModalWindow();
input.ShowDialog();
}