WPF仿网易云搭建笔记(0):项目搭建

文章目录

前言

最近在找工作,发现没有任何的WPF可以拿的出手的工作经验,打算仿照网易云搭建一个WPF版本的。

项目地址

WPF仿网易云 Gitee仓库

项目Nuget包搭建

不管有没有用,先把Nuget装好

项目初始化

我项目初始化用过,我们先简单的项目初始化一下,知识点有点多。我使用的是Prism的BlankApp项目

WPF 零基础入门笔记(1):WPF静态页面,布局+样式+触发器
WPF 零基础入门笔记(2):控件模板+数据模版
WPF 零基础入门笔记(3):数据绑定详解
WPF Material Design UI框架:部分常用控件简单使用
WPF Live Charts2 自学笔记
.NET SqlSuger 简单介绍,超快开发数据库
WPF Prims框架详解
WPF CommunityToolkit.Mvvm
.NET Core 依赖注入 Microsoft.Extensions.DependencyInjection

项目架构

  • Models:实体类
  • Services:服务类
  • Utils:工具类
  • View:视图
  • ViewModels:视图数据
  • ViewStyles:视图样式
  • App.xaml:项目入口

App.xaml引入MateralDesign资源包

xml 复制代码
<prism:PrismApplication x:Class="BlankApp1.App"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:local="clr-namespace:BlankApp1"
                        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
                        xmlns:prism="http://prismlibrary.com/">
    <Application.Resources>
        <ResourceDictionary>
            <!--添加MD 资源包-->
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme BaseTheme="Light"
                                             PrimaryColor="Pink"
                                             
                                             SecondaryColor="Lime" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</prism:PrismApplication>

项目初步分析

这个适合使用DogPanel。

将标题栏去掉

WPF-隐藏窗体标题栏和边框

复制代码
<Window 
		.......
        WindowStyle="None"
        AllowsTransparency="True">

DockPanel初步布局

xml 复制代码
<Window x:Class="BlankApp1.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:MD="http://materialdesigninxaml.net/winfx/xaml/themes"
        xmlns:prism="http://prismlibrary.com/"
        prism:ViewModelLocator.AutoWireViewModel="True"
        xmlns:Views="clr-namespace:BlankApp1.Views"
        WindowStyle="None"
        AllowsTransparency="True"
        Title="{Binding Title}"
        Height="600"
        Width="800">
    <Window.Resources>
        <Style x:Key="ContentBorder"
               TargetType="Border">
            <Setter Property="BorderBrush"
                    Value="Black" />
            <Setter Property="BorderThickness"
                    Value="3" />
        </Style>
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <Border DockPanel.Dock="Bottom"
                Height="70"
                Style="{StaticResource ContentBorder}" />
        <Border DockPanel.Dock="Left"
                Width="100"
                Style="{StaticResource ContentBorder}" />
        <Border DockPanel.Dock="Top"
                Height="60"
                Style="{StaticResource ContentBorder}" />
        
        <Border Style="{StaticResource ContentBorder}"
                Background="Pink"
                Height="auto" />


    </DockPanel>
</Window>

资源字典

我们写样式的时候,有时候样式写的特别多,这样就需要字典引入。这里不得不吐槽,资源字典是没有代码提示的,必须纯手打

xml 复制代码
<!--窗口控件就是Windows.Resource-->
<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/项目名;component/文件完整路径"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

举例

比如我这个资源文件

引入代码

xml 复制代码
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/BlankApp1;component/ViewStyles/TitleStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

记得引入了之后要重新生成一下解决方案,WPF需要重新编译才能识别。

结尾

今天不早了,写完这篇博客已经23:30了,明天有空再接着更新。

相关推荐
王小王-1232 天前
基于 Hive 的网易云音乐数据分析及可视化系统
hive·hadoop·数据分析·音乐数据分析·网易云音乐分析·hive音乐分析·hadoop网易云
闪闪发亮的小星星2 天前
高斯光以及高斯光公式解释
笔记
cqbzcsq2 天前
CellFlow虚拟细胞论文阅读
论文阅读·人工智能·笔记·学习·生物信息
极光代码工作室2 天前
基于数据仓库的电商数据分析平台
大数据·hadoop·python·spark·数据可视化
阿米亚波2 天前
【Windows】QEMU 启动 openEuler aarch64/arm64 架构系统 + 离线软件源
linux·windows·经验分享·笔记·架构·arm
自传.2 天前
尚硅谷 Vibe Coding|第三章(1) Claude Code深度使用与进阶技巧 学习笔记
笔记·学习·尚硅谷·vibecoding
.千余2 天前
【C++】模板进阶全解:非类型参数|全特化|偏特化|分离编译完全指南
开发语言·c++·笔记·学习·其他
自传.2 天前
尚硅谷 Vibe Coding|第二章 AI编程工具生态 学习笔记
笔记·学习·ai编程·尚硅谷·vibe coding
秋波。未央2 天前
Java Agent 开发 · Day 1 学习笔记(含作业完整标准答案)
java·笔记·学习
中屹指纹浏览器2 天前
2026指纹浏览器字体指纹、字体渲染偏差检测与全维度虚拟字体池搭建方案
经验分享·笔记