Thiết kế giao diện app nghe nhạc MP3
App nghe nhạc MP3 crawl data từ mp3.zing.vn

Danh sách bài học
Thiết kế giao diện app nghe nhạc MP3
Chúng ta cùng nhau tìm hiểu cách để làm ra một app nghe nhạc nhé. Đầu tiên là thiết kế giao diện cho ứng dụng.
MainStyle.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MusicAppMP3">
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
</Style>
</ResourceDictionary>
MainWindow.xaml
<Window x:Class="MusicAppMP3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:MusicAppMP3"
xmlns:local="clr-namespace:MusicAppMP3"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
FontFamily="Arial"
Title="MainWindow" Height="650" Width="525">
<Window.Resources>
<ResourceDictionary Source="MainStyle.xaml"></ResourceDictionary>
</Window.Resources>
<Grid>
<Grid x:Name="gridTop10">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<ToggleButton IsChecked="{Binding IsCheckVN}">BXH Việt Nam</ToggleButton>
</Grid>
<Grid Grid.Column="1">
<ToggleButton IsChecked="{Binding IsCheckEU}">BXH Âu Mỹ</ToggleButton>
</Grid>
<Grid Grid.Column="2">
<ToggleButton IsChecked="{Binding IsCheckKO}">BXH Hàn Quốc</ToggleButton>
</Grid>
</Grid>
<Grid Grid.Row="1">
<ListBox x:Name="lsbTopSongs" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Border VerticalAlignment="Stretch" Height="50" BorderThickness="2" BorderBrush="Black">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid>
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center">01</TextBlock>
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid>
<TextBlock HorizontalAlignment="Left">Tên bài hát</TextBlock>
</Grid>
<Grid Grid.Row="1">
<TextBlock HorizontalAlignment="Left">Tên ca sỹ</TextBlock>
</Grid>
</Grid>
<Grid Grid.Column="2">
<Button Click="Button_Click">Play</Button>
</Grid>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
<uc:SongInfoUC x:Name="ucSongInfo" Visibility="Hidden"></uc:SongInfoUC>
</Grid>
</Window>
MainWindow.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MusicAppMP3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
private bool isCheckVN;
private bool isCheckEU;
private bool isCheckKO;
public bool IsCheckVN { get => isCheckVN; set { isCheckVN = value; isCheckEU = false; isCheckKO = false; OnPropertyChanged("IsCheckVN"); OnPropertyChanged("IsCheckEU"); OnPropertyChanged("IsCheckKO"); } }
public bool IsCheckEU { get => isCheckEU; set { isCheckEU = value; isCheckVN = false; isCheckKO = false; OnPropertyChanged("IsCheckVN"); OnPropertyChanged("IsCheckEU"); OnPropertyChanged("IsCheckKO"); } }
public bool IsCheckKO { get => isCheckKO; set { isCheckKO = value; isCheckEU = false; isCheckVN = false; OnPropertyChanged("IsCheckVN"); OnPropertyChanged("IsCheckEU"); OnPropertyChanged("IsCheckKO"); } }
public MainWindow()
{
InitializeComponent();
ucSongInfo.BackToMain += UcSongInfo_BackToMain;
lsbTopSongs.ItemsSource = new List<string>() {"","","","","", "", "", "", "", "" };
this.DataContext = this;
IsCheckVN = true;
}
private void UcSongInfo_BackToMain(object sender, EventArgs e)
{
gridTop10.Visibility = Visibility.Visible;
ucSongInfo.Visibility = Visibility.Hidden;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
gridTop10.Visibility = Visibility.Hidden;
ucSongInfo.Visibility = Visibility.Visible;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string newName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(newName));
}
}
}
}
SongInfoUC.xaml
<UserControl x:Class="MusicAppMP3.SongInfoUC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MusicAppMP3"
mc:Ignorable="d" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="200"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid>
<Button Click="Button_Click">Back</Button>
</Grid>
<Grid Grid.Row="1">
<Button>Play song</Button>
</Grid>
<Grid Grid.Row="2">
<TextBlock>Lyric</TextBlock>
</Grid>
</Grid>
</UserControl>
SongInfoUC.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MusicAppMP3
{
/// <summary>
/// Interaction logic for SongInfoUC.xaml
/// </summary>
public partial class SongInfoUC : UserControl
{
public SongInfoUC()
{
InitializeComponent();
}
private event EventHandler backToMain;
public event EventHandler BackToMain
{
add { backToMain += value; }
remove { backToMain -= value; }
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (backToMain != null)
backToMain(this, new EventArgs());
}
}
}
Tải xuống
Tài liệu
Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học Thiết kế giao diện app nghe nhạc MP3 dưới dạng file PDF trong link bên dưới.
Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com
Đừng quên like và share để ủng hộ Kteam và tác giả nhé!

Thảo luận
Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.
Nội dung bài viết
Tác giả/Dịch giả
Khóa học
App nghe nhạc MP3 crawl data từ mp3.zing.vn
App nghe nhạc MP3 crawl data từ mp3.zing.vn
cghgh
Minh share mà sao khong được công điểm. Đang thiếu điểm học khóa này.
mình đang nghéo quá, đang thất nghiệp nữa, cho nên ko thể ủng hộ web dc, lấy tháng lương đầu tiên sẽ ủng hộ hì
vote cho mình mình sẽ up lên youtube để mọi người cùng học hehe
Ai đó vote cho mình đủ điểm học vs mọi người -_-