从 Win32 API 到 MFC,从 Windows Form 到 WPF(Windows Presentation Foundation),M$上写UI的东东还真是变化多多。
WPF通过xaml来描述布局,通过C#来写事件逻辑,嗯,符合目前UI设计的范式。而且号称“一键发布",可以发布到win32 or web平台,这个看起来不错,哈。
额,我尝试了一下 web 发布,kao,居然是给ie弄了个插件。鬼才用它 - -!
我们来写个小程序看看。
--------------------- HelloWorld.xaml ------------------------
<Window
x:Class="kcode.wpf.HelloWorld"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hello, WPF">
<Button
x:Name="button"
Width="200"
Height="25"
Click="button_Click">Click me</Button>
</Window>
--------------------- HelloWorld.xaml.cs ------------------------
using System;
using System.Windows;
using System.Windows.Controls;
namespace kcode.wpf {
public partial class HelloWorld : Window {
public HelloWorld() {
InitializeComponent();
}
void button_Click(object sender, RoutedEventArgs e) {
MessageBox.Show("Hello");
}
}
}
--------------------------- MyApp.xaml -----------------------------
<Application
x:Class="kcode.wpf.MyApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="AppStartup">
</Application>
--------------------------- MyApp.xaml.cs -----------------------------
using System;
using System.Windows;
namespace kcode.wpf {
public partial class MyApp : Application {
void AppStartup(object sender, StartupEventArgs e) {
Window window = new HelloWorld();
window.Show();
}
}
}
---------------------------- Project.csproj -------------------------------
<Project
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>winexe</OutputType>
<OutputPath>.\</OutputPath>
<AssemblyName>HelloWorld</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ApplicationDefinition Include="MyApp.xaml" />
<Page Include="HelloWorld.xaml" />
<Compile Include="HelloWorld.xaml.cs">
<DependentUpon>HelloWorld.xaml</DependentUpon>
</Compile>
<Compile Include="MyApp.xaml.cs">
<DependentUpon>MyApp.xaml</DependentUpon>
</Compile>
<Reference Include="System" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<Import Project="$(MsbuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MsbuildBinPath)\Microsoft.WinFX.targets" />
</Project>
-------------------------------------------------------------------------------
> msbuild
...
> HelloWorld.exe
-------------------------------------------------------------------------------
哇,看起来还是挺繁琐的。。
评论