在Windows Phone7中存在着多个容器控件,这些控件主要是用来界面的布局设置,以及包容多个控件时的布局设置。

一.Grid控件:主要用于界面的布局,这个和web page里的很相似,可以通过网格布置规划界面,也可以嵌套使用。

<Grid x:Name="LayoutRoot" Background="#DCDCDC" Width="400" Height="300" ShowGridLines="True">    <Grid.ColumnDefinitions>        <ColumnDefinition Width="250" />        <ColumnDefinition Width="150" />    </Grid.ColumnDefinitions>    <Grid.RowDefinitions>        <RowDefinition Height="Auto" />        <RowDefinition Height="2*" />        <RowDefinition Height="*"/>    </Grid.RowDefinitions>    <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" FontWeight="Bold" Text="Contoso Corporation" HorizontalAlignment="Center" VerticalAlignment="Center" />    <Grid x:Name="FormLayoutGrid" Grid.Row="1" Grid.Column="0" ShowGridLines="True">        <Grid.ColumnDefinitions>            <ColumnDefinition Width="Auto" />            <ColumnDefinition />        </Grid.ColumnDefinitions>        <Grid.RowDefinitions>            <RowDefinition Height="*" />            <RowDefinition Height="*" />            <RowDefinition Height="*" />        </Grid.RowDefinitions>        <TextBlock Grid.Row="0" Grid.Column="0" Text="First Name" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" />        <TextBox Grid.Row="0" Grid.Column="1" Margin="10" />        <TextBlock Grid.Row="1" Grid.Column="0" Text="Last Name" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" />        <TextBox Grid.Row="1" Grid.Column="1" Margin="10" />        <TextBlock Grid.Row="2" Grid.Column="0" Text="Address" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" />        <TextBox Grid.Row="2" Grid.Column="1" Margin="10" />

    </Grid> </Grid>

二.Canvas控件:  容器、布局控件,主要是用绝对坐标来定位子控件。对于游戏开发来说用处很大。

<Canvas x:Name="C1"  Grid.Row="2">  <CheckBox x:Name="CheckBox3" Content="CheckBox3" Canvas.Top="50" Canvas.Left="100" Canvas.ZIndex="1" /></Canvas>

也可以使用代码来控制

Canvas.SetLeft();Canvas.SetTop();Canvas.SetZIndex();//控制子控件在Z轴上的顺序。

三.StackPanel控件:容器、布局控件,主要用来多个子控件的纵向、横向的布局控制。

<StackPanel x:Name="stackPanel1" Margin="20" Orientation="Vertical" >   <Rectangle Fill="Red" Width="50" Height="50" Margin="5" />   <Rectangle Fill="Blue" Width="50" Height="50" Margin="5" />   <Rectangle Fill="Green" Width="50" Height="50" Margin="5" />   <Rectangle Fill="Purple" Width="50" Height="50" Margin="5" /></StackPanel>

可以使用下面的方法向上面的StackPanel中动态插入一个Rectangle

private void button1_Click(object sender, RoutedEventArgs e){  Rectangle rect = new Rectangle() { Fill = new SolidColorBrush(Colors.Yellow),Width=50,Height=50};  stackPanel1.Children.Insert(2, rect);}

四.Border控件: 用于包容一个控件并为其绘制边框,并且通过参数设置可以产生多种不同的边框效果。(不太应该算为容器控件,但是又觉得放在别的类里又不是很合适。Jake Lin 和李振都这么分,我采纳了这个观点)

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,12">  <Border Background="Coral" Width="300"  Height="40" Padding="10" CornerRadius="20">    <TextBlock FontSize="16">Text Surrounded by a Border</TextBlock>  </Border>  <Border  x:Name="b1" Width="200" Height="200"  Background="Gold" BorderBrush="Aquamarine" BorderThickness="10, 5, 20, 40"  Margin="119,346,137,49"  CornerRadius="25, 200, 10, 15" >    <TextBox Height="67" Name="textBox1" Text="Test Border" Background="Gold"  Foreground="White" BorderBrush="Gold" Width="170"  VerticalAlignment="Bottom"/>  </Border></Grid>

BorderThickness:边框宽度,设置不同的值使四个边产生不同的宽度。

CornerRadius:边角半径,设置不同的值四个边角产生不同的弧度。

五.PopUp控件:严格来讲这个不应该算作容器控件,但是它可以把包含在其中的控件显示在当前页的最前面,可以被打开和关闭。可以用来制作自定义的MessageBox、WaitingBox等。

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,36,132">            <Image  Source="Images/1.jpg" Height="426" HorizontalAlignment="Left" Margin="25,25,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="386" />            <!-- 这个容器可以被打开和关闭 -->            <Popup IsOpen="True"     HorizontalAlignment="Left" Margin="92,106,0,0" Name="popup1" VerticalAlignment="Top" Height="250" Width="250" >                <Canvas Width="250" Height="250" Background="Red" VerticalAlignment="Center" HorizontalAlignment="Center">                    <TextBlock Margin="30,120,0,0" Text="我在当前页面的上层"/>                </Canvas>            </Popup>        </Grid>        <Button Content="打开" Grid.Row="1" Height="72" HorizontalAlignment="Left" Margin="64,523,0,0" Name="btnOpen" VerticalAlignment="Top" Width="160" Click="btnOpen_Click" />        <Button Content="关闭" Height="72" HorizontalAlignment="Left" Margin="230,523,0,0" Name="btnClose" VerticalAlignment="Top" Width="160" Grid.Row="1" Click="btnClose_Click" />    </Grid>

六.ScrollView:  滚动查看器控件,也算是一个容器控件,它可以用来拖动显示其所包含的控件的内容。

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">            <Canvas>            <!-- A large TextBlock. -->            <!-- A large TextBlock. -->            <TextBlock   Canvas.Top="60" Canvas.Left="-50" Width="400" TextWrapping="Wrap"   Text="I am the very model of a modern Major-General, I've information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical, I understand equations, both the simple and quadratical, About binomial theorem I'm teeming with a lot o' news, With many cheerful facts about the square of the hypotenuse." Margin="78,0,78,201" />

            <!-- The same large TextBlock, wrapped in a ScrollViewer. -->            <!-- It can be scrolled in either direction, since VerticalScrollBarVisibility -->            <!-- has a default value of Visible. -->

<ScrollViewer BorderBrush="Green" BorderThickness="5"  Height="200" Width="300" HorizontalScrollBarVisibility="Auto" Canvas.Top="400" Canvas.Left="80">                <TextBlock  Width="300" TextWrapping="Wrap"     Text="I am the very model of a modern Major-General, I've information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical, I understand equations, both the simple and quadratical, About binomial theorem I'm teeming with a lot o' news, With many cheerful facts about the square of the hypotenuse." />            </ScrollViewer>            </Canvas>        </Grid>

转载于:https://www.cnblogs.com/DebugLZQ/archive/2012/03/28/2422391.html

[Winodows Phone 7控件详解]容器控件相关推荐

  1. [Winodows Phone 7控件详解]控件基础

    Windows Phone7提供了丰富的silverlight控件,但是和silverlight又有一定的区别的,其中有很多控件都是不可用的,另外有些控件即使可以用,但有一些属性也是不可用的.后面将一 ...

  2. [Winodows Phone 7控件详解]控件拾遗

    1.Panorama控件和Pivot控件前面讲过,没有必要再重复一遍了.参见我的博文:http://www.cnblogs.com/DebugLZQ/archive/2012/03/19/240628 ...

  3. [Winodows Phone 7控件详解]Silverlight toolkit for Windows Phone 7.1控件-3

    2.ToggleSwitch 这个开关控件,是windows phone7独有的,Silverlight 没有实现这个控件.这个控件有两个状态Checked 和Unchecked. <Grid ...

  4. [Winodows Phone 7控件详解]Silverlight toolkit for Windows Phone 7.1控件-5

    11年11月初,微软的silverlight toolkit for phone又放出四个新控件,这四个控件使用都要比之前的复杂,并且很有用. 6.AutoCompleteBox 这个控件很像ajax ...

  5. 【转】ASP.NET验证控件详解(非空验证,比较验证,范围验证,正则表达式,自定义验证)...

    [转]ASP.NET验证控件详解(非空验证,比较验证,范围验证,正则表达式,自定义验证) ASP.NET验证控件详解 现在ASP.NET,你不但可以轻松的实现对用户输入的验证,而且,还可以选择验证在服 ...

  6. 常用数据绑定控件详解

    常用数据绑定控件详解 GridView内容详解(1) GridView内容详解(2) DataList内容详解 ListView详解(一) ListView详解(二) 导航控件的高级应用 from:h ...

  7. android自定义组件属性,Android组合控件详解 自定义属性

    组合控件详解 & 自定义属性 组合控件是自定义控件的一种,只不过它是由其他几个原生控件组合而成,故名组合控件. 在实际项目中,GUI 会遇到一些可以提取出来做成自定义控件情况. 一个自定义控件 ...

  8. Switch控件详解

    Switch控件详解 原生效果 5.x 4.x 布局 <Switch android:id="@+id/setting_switch"android:layout_width ...

  9. pythongui日历控件_“五一”快到了,用Python中PyQt5做一个日历,QCalendar控件详解...

    前面内容,我们详细了解了PyQt5中的一些常用控件 精彩内容回顾 Python用PyQt5设计界面,如何正确显示一幅图片,QPixmap控件详解 拥有漂亮的笔刷才能绘制多彩界面,PythonPyQt5 ...

最新文章

  1. VS2015 win64下配置Opencv3.4.7
  2. 步步为营 .NET 代码重构学习笔记 三、内联方法(Inline Method)
  3. PWN-PRACTICE-BUUCTF-20
  4. python输入月份判断季节_用户输入月份,判断这个月是哪个季节。(要求使用列表)_学小易找答案...
  5. Java中的泛型使用
  6. 【题解】CF#403 D-Beautiful Pairs of Numbers
  7. phpstom怎样导出数据库_详解mysql数据库sql优化技巧总结
  8. .bat脚本基本命令合集
  9. EVMC6678L时钟主频配置
  10. 开源库TinyXML2简介及使用
  11. 网易邮箱无法正常登陆的解决技巧
  12. 漏洞解决方案-敏感信息脱敏显示
  13. 哈尔滨计算机毛校长国二,【实验视角】静待紫冰花开 知行合一 且行且知 ——记哈尔滨市实验学校校长王媛参加第二届中国阳明心学高峰论坛...
  14. PAT 甲级1116 1117 1118 1119 解题报告
  15. JavaSE学习笔记(一)基础知识
  16. 【图像检测】基于Itti模型实现图像显著性检测附matlab代码
  17. Verification和Validation
  18. 【CV】图像标准化与归一化
  19. MVC框架的原理详解
  20. Rockchip Android平台挂在samba共享文件夹

热门文章

  1. 新代数控系统参数说明书_台湾新代宏程序编程书
  2. FileIo 删除类中的private方法
  3. 通过反射突破private访问修饰符获取私有和公共的属性,设置和获取值
  4. 我的世界有宠物系统的服务器,我的世界1.6.4宠物战争服务器客户端
  5. mysql里面有没有map类型_MySQL学习(二) 数据类型
  6. 【超级详细的小白教程】Hexo 搭建自己的博客
  7. 剑指offer:50-53记录
  8. 算法(20)-leetcode-剑指offer4
  9. 如何优雅互换Map键与值
  10. signature=4abdf782f13579fc1b57d94a0c6ce95c,β-lactam-associated eosinophilic colitis