官网

https://visualstudio.microsoft.com/zh-hans/vs/

文档

https://docs.microsoft.com/zh-cn/visualstudio/designers/getting-started-with-wpf?view=vs-2019

https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/getting-started/walkthrough-my-first-wpf-desktop-application

第一个WPF桌面应用程序

安装Visual Studio

创建应用程序项目

工作区大概长这样子

写代码测试

  • 编辑MainWindow.xaml(类似安卓开发的xml语言)

在Grid布局中添加

<TextBlock HorizontalAlignment="Left" Margin="252,47,0,0" TextWrapping="Wrap" Text="Select a message option and then choose the Display button." VerticalAlignment="Top"/>
<RadioButton x:Name="HelloButton" Content="Hello" IsChecked="True" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top" Height="30.24" Width="78.107"/>
<RadioButton x:Name="GoodbyeButton" Content="Goodbye" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
<Button Content="Display" Click="Button_Click_1" HorizontalAlignment="Left" Height="40.061" Margin="346.107,245.449,0,0" VerticalAlignment="Top" Width="201.689"/>

(可进行拖拽,放大缩小的图形化操作)

  • 在MainWindow.xmal.ca添加按钮事件

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 WpfApp1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (HelloButton.IsChecked == true)
{
MessageBox.Show("Hello.","提示");
}
else if (GoodbyeButton.IsChecked == true)
{
MessageBox.Show("Goodbye.","提示");
}
}
}
}

其中Button_Click_1与之前xaml中Click对应

  • 启动


小结

C# 开发的WPF对于非专业的开发者可以作为编写小工具的加持,毕竟现在PC桌面开发市场并不景气。

但是抛开市场经济的影响,C#加标记语言的开发模式和Android开发有着异曲同工之妙,殊途同归的设计除了适应场景上的不同,不知道是否会带来对于编程本身更加深刻的认知。

就像刚过中秋的月饼一样,如果摆在面前的有10种月饼,每种月饼有10个,但是只能吃十个,假设从来没有尝过月饼的你是否会每种都去尝试一下呢?

最新文章

  1. Git 安装
  2. ios xcode 下 报出 ”xx“is missing from working copy 的问题
  3. 哈夫曼树(Huffman Tree)与哈夫曼编码
  4. 【POJ】【2125】Destroying the Graph
  5. jquery中Live方法不可用,Jquery中Live方法失效
  6. List(列表)
  7. Html 小插件3
  8. 关于用PS改变图像颜色
  9. css 实现旋转八卦图
  10. String和StringBuffer的区别?
  11. 解决Android Studio编译后安装apk报错:Error while Installing APK
  12. iview form 表单的怪异小BUG
  13. 版本控制git第一篇
  14. Sony笔记本
  15. iOS:使用莱文斯坦距离算法计算两串字符串的相似度
  16. EasyUI表格DataGrid前端分页和后端分页的总结
  17. C#调用Delphi的dll之详解
  18. centos 安装 Vagrant
  19. POST 400 (BAD REQUEST)
  20. error MSB8031

热门文章

  1. Linux 目录递归赋权,解决 Linux权限不够
  2. MySQL--单表查询、多表查询简单概述
  3. 对已经存在的hbase表修改压缩方式
  4. .net测试篇之测试神器Autofixture基本配置一
  5. React 现代化测试
  6. 图解一致性hash算法和实现
  7. Spring学习之旅(八)--SpringMVC请求参数
  8. Dig命令使用大全(转自别人翻译),稍加整理
  9. JNI开发流程
  10. 11_for语句的使用