C# как сохранить данные в списке, а затем добавить их в listview (WPF)
I have Menu in the left side in my window,which has two sections,when i click on first Section Home,opens a page which has 3 textboxes,and three buttons.First button is for uploading music video,in the right side there is groupBox,where i fill that music video's datas` song's name,album,singer's name and again uploading image for song,and Save button,after clicking on Save button,i need save that all datas` Video,image,song's name,album's name,singer's name in List,after saving datas,i need add them in Listview. Listview located in second page,when i click on section Album,opens second page, where shows my saved datas in listview,but it must show only song's name and image. When i click on any item, in the bottom` outside listview, must show that song's video.
Это первая страница[^]
Это вторая страница[^]
class Media { public string SongName; public string Album; public string SingerName; public MediaElement medias; public string Image; public Media(string SongName,string Album, string SingerName,MediaElement medias,string Image) { this.SongName = SongName; this.Album = Album; this.SingerName = SingerName; this.medias = medias; this.Image = Image; } } class Controller { static public List<Media> videos = new List<Media>(); }
//Page 1 public partial class Page1 : Page { public string n; public Page1() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog op = new OpenFileDialog(); if (op.ShowDialog() == true) { mp.Source = new Uri(op.FileName); mp.Play(); } } //This is Save button click,it save datas in Controller class's list private void Button_Click_1(object sender, RoutedEventArgs e) { Media x = new Media(txt1.Text,txt2.Text, txt3.Text,mp,n); Controller.videos.Add(x); } private void Button_Click_3(object sender, RoutedEventArgs e) { OpenFileDialog op = new OpenFileDialog(); op.Title = "Select a picture"; op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; if (op.ShowDialog() == true) { image1.Source = new BitmapImage(new Uri(op.FileName)); } this.n = System.IO.Path.GetFileName(op.FileName); } private void mp_MouseEnter(object sender, MouseEventArgs e) { mp.Pause(); } private void mp_MouseLeave(object sender, MouseEventArgs e) { mp.Play(); } } //This is Page 2 public partial class Page2 : Page { public Page2() { InitializeComponent(); foreach (var videos in Controller.videos) //add datas in ListView { var add = string.Format("{0} {1}", videos.SongName,videos.Image); lv.Items.Add(add); } } }
// Page 1 XAML <Grid Background="#FF35A69C"> <Button Click="Button_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20" Content="Upload Video" FontSize="30" Height="80" Width="250" Background="Aqua"/> <MediaElement MouseEnter="mp_MouseEnter" MouseLeave="mp_MouseLeave" x:Name="mp" LoadedBehavior="Manual" Height="290" Width="450" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10 110"/> <GroupBox Header="Edit" FontSize="20" Background="White" Foreground="Aqua" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20" Height="500" Width="500"> <Grid> <TextBlock Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" Width="120" FontSize="20" Text="Song Name"/> <TextBox x:Name="txt1" Height="40" Width="200" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10 40"/> <TextBlock Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10 80" Width="120" FontSize="20" Text="Album"/> <TextBox x:Name="txt2" Height="40" Width="200" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10 110"/> <TextBlock Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10 150" Width="120" FontSize="20" Text="Singer Name"/> <TextBox x:Name="txt3" Height="40" Width="200" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="13,179,0,0"/> <Button Click="Button_Click_3" Height="60" Width="160" Background="Aqua" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10 120" Content="Choose Image" FontSize="20"/> <Button HorizontalAlignment="Right" Margin="0,0,310,40" Content="Save" FontSize="30" Background="Aqua" Click="Button_Click_1" Height="60" Width="160" VerticalAlignment="Bottom"/> <Image x:Name="image1" Height="280" Width="240" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="10 40"/> </Grid> </GroupBox> </Grid> //Page 2 XAML <Grid Background="#FF35A69C"> <GroupBox Background="White" Header="My Songs" FontSize="20" Height="200" Width="600" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20"> <ListView x:Name="lv"> </ListView> </GroupBox> </Grid>
Что я уже пробовал:
Как я могу это сделать, это изображение показывает в listview, теперь оно показывает вот так ` элемент управления ListView[^]
Мне нужно название песни и рядом с ним или под ним изображение.И как я могу это сделать, например,когда я нажимаю на любую песню, внизу воспроизводится видео этой песни, которое я сохранил в списке. Подобный этому[^]
Спасибо.