I'm making a music player in C# WPF. Files are added to a ListBox which works as the playlist for the MediaElement. In order to only show the filename without path and extension in the ListBox, I made a Song
class which has properties for path and title.
What I can't figure out is how to set the MediaElements source to the path property of the Song
object, so that I can just click an item in the ListBox and it would start playing.
Here's the code I use for adding files to the listbox:
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (string file in ofd.FileNames)
{
Song songs = new Song(System.IO.Path.GetFileNameWithoutExtension(file), file);
listBox.Items.Add(songs);
}
}