一直期待GUI,有了方便的GUI才能方便得到友好的应用.html,css,js有浏览器,c#的xaml有vs和图形视图,都是描述性语言.
操作流程:新建项目-C#-WPF - 转到MainWindow.xaml.cs的视图-工具|属性- 动手吧 | 调整下xaml文档 - 点击需要事件的控件 - 编辑方法;
新方法:MessageBox.Show();消息窗口;
代码流程:先app.xaml-app.xaml.cs-mainwindow.xaml-mainwindow.xaml.cs; 估计作者表达的是这个意思
代码:
App.xaml
<Application x:Class="WPFHello.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <!--StartupUri= 就文字而言,启动uri,这里引用了别的文件(代码)--> <Application.Resources> </Application.Resources></Application>App.xaml.cs
using System;
using System.Collections.Generic;using System.Configuration;using System.Data;using System.Linq;using System.Windows;namespace WPFHello
{ /// <summary> /// App.xaml 的交互逻辑 /// </summary> public partial class App : Application { //这里Main方法被隐藏,因为他需要根据app.xaml被动态生成 }}MainWindow.xaml:
<Window x:Class="WPFHello.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="hello" Height="350" Width="525"> <!--发现标签里没法注释, 注意下最上面的Class= 和Title=--> <Grid> <Label Content="Please enter your name " Height="33" HorizontalAlignment="Left" Margin="161,54,0,0" Name="label1" VerticalAlignment="Top" Width="163" /> <TextBox Height="22" HorizontalAlignment="Left" Margin="166,81,0,0" Name="userName" VerticalAlignment="Top" Width="105" /> <Button Content="ok" Height="23" HorizontalAlignment="Left" Margin="277,80,0,0" Name="OK" VerticalAlignment="Top" Width="21" Click="ok_Click" /> </Grid></Window>MainWindow.xaml.cs
using System;
using System.Collections.Generic;using System.Linq;using System.Text;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 WPFHello
{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window {//有构造有返回值,复习下构造是没返回值和类名相同的方法 //C#程序的执行也需要Main方法为入口, //就解决方案的文件结构而言,一个xaml下会有一个.xaml.cs文件 这是 .jsp和 .class的关系吗? //记住.cs是C#的源代码,像code source public MainWindow() { InitializeComponent(); } //方法自动生成好便捷 private void ok_Click(object sender, RoutedEventArgs e) {//userName这个变量来自xaml文件的定义 //根据变量值的定义变量名,这到方便 //又发现方法的调用也是xaml里写好方法名,按照xaml里的调用 //xaml里定义的东西找不到的话编译会报错 MessageBox.Show("Hello " + userName.Text); //userName.Text;Text算啥?属性? } }} posted on 2017-11-01 22:45 阅读( ...) 评论( ...)