代码所在位置:
WPFSamples/Intro/QuickStart1
这个例子,可以认为是
WPF
应用的
Hello Worldchen
程序
目录下面一共有两个
XAML
文件
MyApp.xaml
和
Page1.xaml
XAML
是
XML
的一个子集,如果熟悉
XML
或者
HTML
的人会很容易看懂,不熟悉的也能很容易看懂
J
MyApp.xaml
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Page1.xaml">
</Application>
MyApp.xaml
文件中
使用
[Application]
标签定义了一个应用
通过
StartupUri="Page1.xaml"
定义了一个应用(
Application
)的启动页面为
Page1.xaml
下面再看
Page1.xaml
Page1.xaml
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<StackPanel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock>
Hello, World!
</TextBlock>
</StackPanel>
</Page>
Page1.xaml
文件中使用
[Page]
标签定义页面。
然后定义了页面的一个布局
(LayOut)
为
[StackPanel]
,当然,
XAML
中还有许多其他类型的布局,在以后会逐一介绍的,大家先不用着急。
接着,在
[StackPanel]
的内部定义了一个
[TextBlock]
这样在页面上就会显示一个
TextBlock
,其内容为
Hello, World!
程序编译之后的运行截图如下:
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=866590