WPF仿网易云音乐系列(一、歌单创建窗口+登录设置模块)

  之前上一篇随笔,我看了下评论,有部分人说WPF已经凉凉了,这个我觉得,这只是一个达到自己目的的工具而已,只要自己能用这个工具,得心应手的做出自己想要的东西就行,关心工具本身凉了没,个人觉得没啥意义;另外,我一个做Java的都没泼凉水,你.Net自己的东西,你们还不满意了,太过分了,haha;

  以上,瞎bb一通,轻喷...下面开始正题;

一.简介

  上一篇文章,咱们利用Expander+RadioButton实现了左侧菜单栏(或者是导航栏),这一片随笔,做创建歌单窗口和登录设置按钮那一坨...咱们先来看看原版长啥样子

WPF仿网易云音乐系列(一、歌单创建窗口+登录设置模块)

WPF仿网易云音乐系列(一、歌单创建窗口+登录设置模块)

  看上去蛮厉害的样子,咱们开始搞一搞;

二.正文

创建歌单窗口

  首先需要创建一个窗口。。然后设置WindowStyle="None" 使窗口无边框化;另外,窗口在弹出的时候,是有一个蒙版效果的;这里咱们还需要给他加上蒙版;话不多说,上代码;

窗体xmal

WPF仿网易云音乐系列(一、歌单创建窗口+登录设置模块)

WPF仿网易云音乐系列(一、歌单创建窗口+登录设置模块)

1 <Window x:Class="CloudMusic.CreateAlbum" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:CloudMusic" 7 mc:Ignorable="d" 8 Foreground="#444" 9 Closed="CreateAlbumWindow_Closed" 10 ShowInTaskbar="False" 11 WindowStyle="None" 12 WindowStartupLocation="CenterOwner" 13 Title="CreateAlbum" Height="250" Width="430"> 14 <Window.Resources> 15 <!--文本操作右键菜单--> 16 <ContextMenu x:Key="TextBoxContextMenu" > 17 <MenuItem Command="ApplicationCommands.Cut" /> 18 <MenuItem Command="ApplicationCommands.Copy" /> 19 <MenuItem Command="ApplicationCommands.Paste" /> 20 <MenuItem Command="ApplicationCommands.SelectAll" /> 21 </ContextMenu> 22 </Window.Resources> 23 <Grid> 24 <Grid.RowDefinitions> 25 <RowDefinition Height="45"/> 26 <RowDefinition Height="*"/> 27 </Grid.RowDefinitions> 28 <StackPanel Grid.Row="0"> 29 <TextBlock Text="新建歌单" FontSize="18" Margin="10"/> 30 <Border BorderBrush="#A7A7A7" BorderThickness="0.3"/> 31 </StackPanel> 32 <StackPanel Grid.Row="1"> 33 <TextBox Name="CreateAlbumTitle" Grid.Row="0" Tag="20" Margin="20" Height="40" TextChanged="CreateAlbumTitle_TextChanged" FontSize="14"> 34 <TextBox.Style> 35 <Style TargetType="TextBox"> 36 <Setter Property="ContextMenu" Value="{DynamicResource TextBoxContextMenu}" /> 37 <Setter Property="Template"> 38 <Setter.Value> 39 <ControlTemplate TargetType="{x:Type TextBox}"> 40 <Border x:Name="border" Width="Auto" Height="Auto" BorderThickness="1" BorderBrush="#A7A7A7"> 41 <Grid x:Name="grid" Background="#FFFFFF"> 42 <ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" HorizontalAlignment="Left"/> 43 <TextBlock x:Name="x" Visibility="Collapsed" Foreground="#A7A7A7" Text="歌单标题" 44 VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Microsoft YaHei"/> 45 <TextBlock Margin="5,0" x:Name="x1" Foreground="#A7A7A7" Text="{TemplateBinding Tag}" 46 VerticalAlignment="Center" HorizontalAlignment="Right" FontFamily="Microsoft YaHei"/> 47 </Grid> 48 </Border> 49 <ControlTemplate.Triggers> 50 <Trigger Property="Text" Value="{x:Null}"> 51 <Setter Property="Visibility" TargetName="x" Value="Visible"></Setter> 52 </Trigger> 53 <Trigger Property="Text" Value=""> 54 <Setter Property="Visibility" TargetName="x" Value="Visible"></Setter> 55 </Trigger> 56 </ControlTemplate.Triggers> 57 </ControlTemplate> 58 </Setter.Value> 59 </Setter> 60 <Style.Triggers> 61 62 <Trigger Property="IsMouseOver" Value="True"> 63 <Setter Property="Background" Value="Transparent"/> 64 <Setter Property="Foreground" Value="#444"/> 65 </Trigger> 66 <Trigger Property="IsFocused" Value="True"> 67 <Setter Property="Background" Value="Transparent"/> 68 <Setter Property="Foreground" Value="#444"/> 69 </Trigger> 70 <Trigger Property="IsEnabled" Value="False"> 71 <Setter Property="Background" Value="Transparent"/> 72 <Setter Property="Foreground" Value="#444"/> 73 </Trigger> 74 </Style.Triggers> 75 </Style> 76 </TextBox.Style> 77 </TextBox> 78 <CheckBox Margin="20,20" Foreground="#A7A7A7"> 79 设置为隐私歌单 80 </CheckBox> 81 <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="20,10"> 82 <Button Style="{StaticResource ColorButton}" Width="100" Height="35" FontSize="16" 83 Click="Button_Click_1"> 84 新建 85 </Button> 86 <Button Style="{StaticResource ColorButton}" Margin="20,0,0,0" Width="100" 87 Height="35" FontSize="16" Click="Button_Click" 88 Background="White" Foreground="{StaticResource MainColor}">取消</Button> 89 </StackPanel> 90 </StackPanel> 91 </Grid> 92 </Window>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zygppf.html