热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

WPF系列教程——(一)仿TIMQQ界面简书

原文:WPF系列教程——(一)仿TIMQQ界面-简书TIMQQ我们先来看一下TIMQQ长什么样,整体可以将界面分为三个部分TIMQQ1.准备阅读本文假设你已经有XAML布局的基础,

原文:WPF系列教程——(一)仿TIM QQ界面 - 简书



TIM QQ

我们先来看一下TIM QQ长什么样,整体可以将界面分为三个部分





技术分享图片


TIM QQ


1. 准备

  • 阅读本文假设你已经有XAML布局的基础,所以只对部分布局进行说明。

  • 界面上的图标均来自 Material Design Icons
    选择需要的图标后点击View XAML



    技术分享图片


    图片.png


    会显示WPF的调用代码,直接复制到项目中即可,WPF是支持矢量图显示的。



    技术分享图片


    图片.png





  • 本文中的控件使用了开源的MaterialDesignInXamlToolkit,这是一款WPF的Material Design UI库,也是WPF最流行的UI库之一,可以轻松的做出漂亮的界面,到NuGet中搜索即可添加到项目。



    技术分享图片


    NuGet


    App.xaml文件中,添加以下代码,应用资源样式
    Color表示所有控件的主题颜色,不添加的话所有控件颜色默认为紫色。

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#1C93EC" />
ResourceDictionary>

在需要使用MaterialDesignInXamlToolkit控件的页面引入命名空间
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"


  • 使用Grid布局将页面划分为三个区域,感觉Grid是万能布局,可以用它设计出大多数软件90%的界面

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="63*" />
<RowDefinition Height="706*" />
Grid.RowDefinitions>
<Grid Grid.Row="0">
Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="157*" />
<ColumnDefinition Width="389*" />
Grid.ColumnDefinitions>
<Grid Grid.Column="0">

Grid>
<Grid Grid.Column="1">

Grid>
Grid>
Grid>




技术分享图片


三个区域


2. 圆形头像

在WPF上显示圆形图片很简单,使用Ellipse绘制圆形设置宽和高一致绘制正圆,在内部使用Image笔刷填充图片,本文中的头像显示方式均以此来实现。

<Ellipse Width="50"
Height="50">

<Ellipse.Fill>
<ImageBrush ImageSource="Images/github.png" />
Ellipse.Fill>
Ellipse>

3. 工具栏设计

工具栏的三个不同几何图形,使用Polygon来绘制,再将内部填充不同的颜色,坐标自行测试选择适当位置。




技术分享图片


工具栏


第一个多边形

<Polygon Points="0,0 700,0 756,65 0,65"
StrokeThickness="1">

<Polygon.Fill>
<SolidColorBrush Color="#1C93EC" />
Polygon.Fill>
Polygon>

第二个多边形

<Polygon Points="700,0 780,0 740,50 "
StrokeThickness="1">

<Polygon.Fill>
<SolidColorBrush Color="#3E58C9" />
Polygon.Fill>
Polygon>

第三个多边形

<Polygon Points="780,0 1100,0 1100,65 723,65 "
StrokeThickness="1">

<Polygon.Fill>
<SolidColorBrush Color="#3448A1" />
Polygon.Fill>
Polygon>

XAML代码如下,简书没有折叠代码功能啊,这段有点长。

<materialDesign:ColorZone Mode="PrimaryMid"
Name="NavBar"
Height="65"
MouseLeftButtonDown="NavBar_MouseLeftButtonDown"
materialDesign:ShadowAssist.ShadowDepth="Depth3">

<Grid>

<Polygon Points="780,0 1100,0 1100,65 723,65 "
StrokeThickness="1">

<Polygon.Fill>
<SolidColorBrush Color="#3448A1" />
Polygon.Fill>
Polygon>

<Polygon Points="700,0 780,0 740,50 "
StrokeThickness="1">

<Polygon.Fill>
<SolidColorBrush Color="#3E58C9" />
Polygon.Fill>
Polygon>

<Polygon Points="0,0 700,0 756,65 0,65"
StrokeThickness="1">

<Polygon.Fill>
<SolidColorBrush Color="#1C93EC" />
Polygon.Fill>
Polygon>
<Ellipse Cursor="Hand"
HorizontalAlignment="Left"
Margin="10 5"
Width="50"
Height="50">

<Ellipse.Fill>
<ImageBrush ImageSource="Images/github.png" />
Ellipse.Fill>
Ellipse>
<Grid HorizontalAlignment="Center"
Width="200">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Button Width="60"
Height="60"
Background="{x:Null}"
BorderBrush="{x:Null}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
Padding="0">

<Viewbox Width="30"
Height="30">

<Canvas Width="24"
Height="24">

<Path Data="M17,12V3A1,1 0 0,0 16,2H3A1,1 0 0,0 2,3V17L6,13H16A1,1 0 0,0 17,12M21,6H19V15H6V17A1,1 0 0,0 7,18H18L22,22V7A1,1 0 0,0 21,6Z"
Fill="White" />

Canvas>
Viewbox>
Button>
Grid>
<Grid Grid.Column="1">
<Button Width="60"
Height="60"
Background="{x:Null}"
BorderBrush="{x:Null}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
Padding="0">

<Viewbox Width="30"
Height="30">

<Canvas Width="24"
Height="24">

<Path Data="M16.5,12A2.5,2.5 0 0,0 19,9.5A2.5,2.5 0 0,0 16.5,7A2.5,2.5 0 0,0 14,9.5A2.5,2.5 0 0,0 16.5,12M9,11A3,3 0 0,0 12,8A3,3 0 0,0 9,5A3,3 0 0,0 6,8A3,3 0 0,0 9,11M16.5,14C14.67,14 11,14.92 11,16.75V19H22V16.75C22,14.92 18.33,14 16.5,14M9,13C6.67,13 2,14.17 2,16.5V19H9V16.75C9,15.9 9.33,14.41 11.37,13.28C10.5,13.1 9.66,13 9,13Z"
Fill="White" />

Canvas>
Viewbox>
Button>
Grid>
<Grid Grid.Column="2">
<Button Width="60"
Height="60"
Background="{x:Null}"
BorderBrush="{x:Null}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
Padding="0">

<Viewbox Width="30"
Height="30">

<Canvas Width="24"
Height="24">

<Path Data="M19,16A3,3 0 0,0 22,13A3,3 0 0,0 19,10H17.5V9.5A5.5,5.5 0 0,0 12,4C9.5,4 7.37,5.69 6.71,8H6A4,4 0 0,0 2,12A4,4 0 0,0 6,16V11H18V16H19M19.36,8.04C21.95,8.22 24,10.36 24,13A5,5 0 0,1 19,18H18V22H6V18A6,6 0 0,1 0,12C0,8.91 2.34,6.36 5.35,6.04C6.6,3.64 9.11,2 12,2C15.64,2 18.67,4.6 19.36,8.04M8,13V20H16V13H8M9,18H15V19H9V18M15,17H9V16H15V17M9,14H15V15H9V14Z"
Fill="White" />

Canvas>
Viewbox>
Button>
Grid>
Grid>
<Grid HorizontalAlignment="Right"
Width="150">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Button Height="60"
Background="{x:Null}"
BorderBrush="{x:Null}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
Padding="0">

<Viewbox Width="25"
Height="25">

<Canvas Width="24"
Height="24">

<Path Data="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z"
Fill="White" />

Canvas>
Viewbox>
Button>
Grid>
<Grid Grid.Column="1">
<Button Height="60"
Background="{x:Null}"
BorderBrush="{x:Null}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
Padding="0">

<Viewbox Width="25"
Height="25">

<Canvas Width="24"
Height="24">

<Path Data="M20,14H4V10H20"
Fill="White" />

Canvas>
Viewbox>
Button>
Grid>
<Grid Grid.Column="2">
<Button Height="60"
Background="{x:Null}"
BorderBrush="{x:Null}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
Padding="0">

<Viewbox Width="25"
Height="25">

<Canvas Width="24"
Height="24">

<Path Data="M4,4H20V20H4V4M6,8V18H18V8H6Z"
Fill="White" />

Canvas>
Viewbox>
Button>
Grid>
<Grid Grid.Column="3">
<Button Height="60"
Background="{x:Null}"
BorderBrush="{x:Null}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
Padding="0">

<Viewbox Width="25"
Height="25">

<Canvas Width="24"
Height="24">

<Path Data="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"
Fill="White" />

Canvas>
Viewbox>
Button>
Grid>
Grid>
Grid>
materialDesign:ColorZone>

4. 好友列表设计

好友列表使用了ListView,效果图中的好友都是静态的数据,列表绑定会在下一节讲到。





技术分享图片


好友列表

"#FAFAFA"
Grid.Column="0">
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Cursor="Hand">

ListView>

"{StaticResource MaterialDesignMultiFloatingActionPopupBox}"
PlacementMode="TopAndAlignCentres"
ToolTipService.Placement="Left"
ToolTip="TIM QQ"
HorizOntalAlignment="Right"
VerticalAlignment="Bottom"
Margin="20">
materialDesign:PopupBox>
Grid>

ListView中Item代码如下

<ListViewItem Height="60"
Padding="0">

<StackPanel Orientation="Horizontal"
Margin="10 0">

<Ellipse Cursor="Hand"
Width="50"
Height="50">

<Ellipse.Fill>
<ImageBrush ImageSource="Images/head2.jpg" />
Ellipse.Fill>
Ellipse>
<StackPanel Orientation="Vertical"
VerticalAlignment="Center"
Margin="5 0">

<TextBlock FontSize="15"
Foreground="Black"
Text="糖宝" />

<TextBlock Margin="0 2 0 0"
FontSize="12"
Text="Hello world" />

StackPanel>
StackPanel>
ListViewItem>

5. 名片设计

名片页面是不是和TIM QQ的几乎一模一样~





技术分享图片


名片

XAML代码如下

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
Grid.RowDefinitions>
<Grid Grid.Row="0">
<Image Stretch="UniformToFill" Source="Images/head1.jpg" />
Grid>
<Grid Grid.Row="1">
<Button Style="{StaticResource MaterialDesignFloatingActionButton}"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0 -30 5 0"

BorderBrush="{x:Null}"
ToolTip="修改资料">

<materialDesign:PackIcon Kind="Pencil"
Height="24"
Width="24" />

Button>
<StackPanel Orientation="Vertical">
<TextBlock Text="Go to hell!"
HorizontalAlignment="Center"
FontSize="35"
Margin="0 20 0 0" />

<StackPanel Orientation="Horizontal"
Margin="80 5 0 0 "

>

<TextBlock Text="账号 "
Foreground="#B7B7B7" />

<TextBlock Text="vaemc520@qq.com" />
StackPanel>
<StackPanel Orientation="Horizontal"
Margin="80 5 0 0 ">

<TextBlock Text="昵称 "
Foreground="#B7B7B7" />

<TextBlock Text="Go to hell!" />
StackPanel>
<StackPanel Orientation="Horizontal"
Margin="80 5 0 0 ">

<TextBlock Text="手机 "
Foreground="#B7B7B7" />

<TextBlock Text="183XXXXXXXX" />
StackPanel>
<StackPanel Orientation="Horizontal"
Margin="80 5 0 0 ">

<TextBlock Text="邮箱 "
Foreground="#B7B7B7" />

<TextBlock Text="vaemc520@qq.com" />
StackPanel>
<StackPanel Orientation="Horizontal"
Margin="80 5 0 0 ">

<TextBlock Text="职业 "
Foreground="#B7B7B7" />

<TextBlock Text="计算机/互联网/通信" />
StackPanel>
<StackPanel Orientation="Horizontal"
Margin="80 5 0 0 ">

<TextBlock Text="空间 "
Foreground="#B7B7B7" />

<TextBlock Text="Go to hell! 的空间" />
StackPanel>
StackPanel>
Grid>

6. 最终效果




技术分享图片


最终效果

欢迎Star https://github.com/vaemc/WpfTimQQ

7. 总结

接触到了WPF以后感觉用WinForm托控件真的好LOW,并且用WPF可以轻松的设计出好看的界面,以前经常写安卓也发现这俩玩意布局竟如此的雷同,然后就慢慢的过度到了WPF。
下一节将会以此项目为基础来讲诉WPF MVVM框架的实现,欢迎关注~



推荐阅读
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 在project.properties添加#Projecttarget.targetandroid-19android.library.reference.1..Sliding ... [详细]
  • 本文介绍了一种解析GRE报文长度的方法,通过分析GRE报文头中的标志位来计算报文长度。具体实现步骤包括获取GRE报文头指针、提取标志位、计算报文长度等。该方法可以帮助用户准确地获取GRE报文的长度信息。 ... [详细]
  • vue使用
    关键词: ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
author-avatar
dongmyee
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有