传统的应用程序平台(如 Win32)几乎没有布局的概念:控件放置在画布上的 (x,y) 坐标系中,并且开发人员需要手动提供对确定任何元素的原点和尺寸的支持(考虑窗口大小调整和显示器 DPI 设置)。另一方面,Windows Presentation Foundation 提供多种适合于内容并且在窗口内管理控件和项目位置的布局实现。
下面的代码直接拷贝到XamlPad中就可以看到效果(XamlPad在什么地方?安装Framework3.0 SDK就可以了)
--->示例1:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid>
<Image Source="C:\WINDOWS\Web\Wallpaper\follow.jpg" />
<Button Width="100" Height="50" Content="这就是一个测试" />
</Grid>
</Page>
--->示例2:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid>
<Button Width="400" Height="300" >
<Image Source="C:\WINDOWS\Web\Wallpaper\follow.jpg" />
</Button>
</Grid>
</Page>
Button 可按上面方式包含图像,Button成为Image控件的宿主。
此外,Windows Presentation Foundation 提供五个布局面板,以便控制和约束子元素的大小和位置:Canvas、DockPanel、StackPanel Grid 和 WrapPanel。
下面的代码直接拷贝到XamlPad中就可以看到效果(XamlPad在什么地方?安装Framework3.0 SDK就可以了)
--->示例1:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid>
<Image Source="C:\WINDOWS\Web\Wallpaper\follow.jpg" />
<Button Width="100" Height="50" Content="这就是一个测试" />
</Grid>
</Page>
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid>
<Button Width="400" Height="300" >
<Image Source="C:\WINDOWS\Web\Wallpaper\follow.jpg" />
</Button>
</Grid>
</Page>此外,Windows Presentation Foundation 提供五个布局面板,以便控制和约束子元素的大小和位置:Canvas、DockPanel、StackPanel Grid 和 WrapPanel。
