win8/Metro开发系列一 Xaml布局

首先要懂得一些基础的布局知识,这样在开发的过程中才能游刃有余.

布局主要写到xam里面,在xaml基本的主要涉及到三个布局控件Canvas,StackPanel,Grid

概括起来很简单

1.Canvas就是根据坐标、大小进行绝对定位布局。

示例代码

1 <Canvas>
2             <Button Canvas.Left="28" Canvas.Top="26" Content="Button" Height="45" Width="92" />
3 </Canvas>

 

Canvas.Top属性指定控件左上角的纵坐标; Canvas.Left属性指定控件左上角的横坐标。

由于Canvas是绝对定位我没怎么用过只简单的说下 ,用的最多的还是他的z-index的附加属性;

补充:代码设置TopLeft等附加属性的方法:Canvas.SetTop
 
2.StackPanel是把子控件横向或者纵向排列。用Orientation属性设定排列方向:Horizontal(水平)、Vertical(纵向,默认)
示例代码:
View Code

3.Grid他类似于html的<Table></Table>标签,由于我是从web开发转过来的所以特别喜欢它,基本上和table类似由行和列构成的

<RowDefinition ><ColumnDefinition >可以用这俩属性类定义他的行和列,并用Grid.Row,Grid.Column附加属性,来设置grid容器里的空间位于哪行哪列,Grid.RowSpan等可以用来跨行列,总之很方面

注:在用来定义行列大小高度的时候还可以用百分比,稍微变动不是加%而是用*,默认width=“1*”是平分高了分得多少了分的少可以自己去感受下同时*是表示剩下的全部,Auto:自动

此外这些基本布局控件,都是容器,就像你的web开发中的div就Ok了~还会有一个一开始我经常犯得错误!就是button的content属性他是Object类型想对里装俩控件会报错说存在重复的属性,其实想通了很简单你给content赋值给他同时赋俩值它没那么智能不知道你到底想给他赋什么所以就报错了,这时你只需要给他一个容器包裹着再赋给它就Ok了!

下面闲话少扯泳用这些基本的控件来布局一个

这是做的项目的第一页截图接下来就看其简单的实现,这是一开始尝试做的没用样式和资源比较繁琐和乱套,下节用样式和资源来重构一下,不过对练布局还好吧

代码示例:

复制代码
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition ></RowDefinition>
            <RowDefinition Height="3.5*"></RowDefinition>
            <RowDefinition ></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition ></ColumnDefinition>
            <ColumnDefinition Width="8*"></ColumnDefinition>
            <ColumnDefinition ></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <TextBlock Text="妙笔生花" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="50,60,0,0" FontSize="48"></TextBlock>
        <Grid Grid.Column="1" Grid.Row="1" Name="auto">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Button  Grid.Row="0" Grid.Column="0" Click="OnClick">
                <Button.Content>
                    <ContentControl>
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="4*" ></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Image Source="Images/Grop_Item00.jpg" Grid.RowSpan="2" ></Image>
                            <Image Grid.Row="1" Source="Images/11.png"></Image>
                            <TextBlock Text="电脑对联生成器"   Grid.Row="1" FontSize="30" HorizontalAlignment="Center">
                                <TextBlock.Foreground>
                                    <ImageBrush ImageSource="Images/background.png">
                                    </ImageBrush>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </Grid>
                    </ContentControl>
                </Button.Content>
            </Button>
            <Button  Grid.Row="0" Grid.Column="1" Click="OndicClick">
                <Button.Content>
                    <ContentControl>
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="4*" ></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Image Source="Images/Grop_Item10.jpg" Grid.RowSpan="2" ></Image>
                            <Image Grid.Row="1" Source="Images/11.png"></Image>
                            <TextBlock Text="中华大字典"   Grid.Row="1" FontSize="30" HorizontalAlignment="Center"  >
                                <TextBlock.Foreground>
                                    <ImageBrush ImageSource="Images/backGround.png">
                                    </ImageBrush>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </Grid>
                    </ContentControl>
                </Button.Content>
            </Button>
            <Button  Grid.Row="0" Grid.Column="2">
                <Button.Content>
                    <ContentControl>
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="4*" ></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Image Source="Images/Grop_Item02.jpg" Grid.RowSpan="2" ></Image>
                            <Image Grid.Row="1" Source="Images/11.png"></Image>
                            <TextBlock Text="诗歌生成器"   Grid.Row="1" FontSize="30" HorizontalAlignment="Center"  >
                                <TextBlock.Foreground>
                                    <ImageBrush ImageSource="Images/backGround.png">
                                    </ImageBrush>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </Grid>
                    </ContentControl>
                </Button.Content>
            </Button>
            <Button  Grid.Row="1" Grid.Column="0">
                <Button.Content>
                    <ContentControl>
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="4*" ></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Image Source="Images/Grop_Item01.jpg" Grid.RowSpan="2" ></Image>
                            <Image Grid.Row="1" Source="Images/11.png"></Image>
                            <TextBlock Text="趣味经典对联"   Grid.Row="1" FontSize="30" HorizontalAlignment="Center"  >
                                <TextBlock.Foreground>
                                    <ImageBrush ImageSource="Images/backGround.png">
                                    </ImageBrush>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </Grid>
                    </ContentControl>
                </Button.Content>
            </Button>
            <Button  Grid.Row="1" Grid.Column="1" Click="OnPoetryClick">
                <Button.Content>
                    <ContentControl>
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="4*" ></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Image Source="Images/Grop_Item11.jpg" Grid.RowSpan="2" ></Image>
                            <Image Grid.Row="1" Source="Images/11.png"></Image>
                            <TextBlock Text="诗歌大全"   Grid.Row="1" FontSize="30" HorizontalAlignment="Center"  >
                                <TextBlock.Foreground>
                                    <ImageBrush ImageSource="Images/backGround.png">
                                    </ImageBrush>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </Grid>
                    </ContentControl>
                </Button.Content>
            </Button>
            <Button  Grid.Row="1" Grid.Column="2" Click="OnallegoricalClick">
                <Button.Content>
                    <ContentControl>
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="4*" ></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Image Source="Images/Grop_Item12.jpg" Grid.RowSpan="2" ></Image>
                            <Image Grid.Row="1" Source="Images/11.png"></Image>
                            <TextBlock Text="歇后语大全"   Grid.Row="1" FontSize="30" HorizontalAlignment="Center"  >
                                <TextBlock.Foreground>
                                    <ImageBrush ImageSource="Images/backGround.png">
                                    </ImageBrush>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </Grid>
                    </ContentControl>
                </Button.Content>
            </Button>
        </Grid>
    </Grid>
复制代码

仅个人意见,初学还有很多不懂欢迎大家批评指导

关于 阿里云盘CLI。仿 Linux shell 文件处理命令的阿里云盘命令行客户端,支持JavaScript插件,支持同步备份功能,支持相册批量下载。 特色 多平台支持, 支持 Windows, macOS, linux(x86/x64/arm), android, iOS 等 阿里云盘多用户支持 支持备份盘,资源库无缝切换 下载网盘内文件, 支持多个文件或目录下载, 支持断点续传和单文件并行下载。支持软链接(符号链接)文件。 上传本地文件, 支持多个文件或目录上传,支持排除指定文件夹/文件(正则表达式)功能。支持软链接(符号链接)文件。 同步备份功能支持备份本地文件到云盘,备份云盘文件到本地,双向同步备份保持本地文件和网盘文件同步。常用于嵌入式或者NAS等设备,支持docker镜像部署。 命令和文件路径输入支持Tab键自动补全,路径支持通配符匹配模式 支持JavaScript插件,你可以按照自己的需要定制上传/下载中关键步骤的行为,最大程度满足自己的个性化需求 支持共享相册的相关操作,支持批量下载相册所有普通照片、实况照片文件到本地 支持多用户联合下载功能,对下载速度有极致追求的用户可以尝试使用该选项。详情请查看文档多用户联合下载 如果大家有打算开通阿里云盘VIP会员,可以使用阿里云盘APP扫描下面的优惠推荐码进行开通。 注意:您需要开通【三方应用权益包】,这样使用本程序下载才能加速,否则下载无法提速。 Windows不第二步打开aliyunpan命令行程序,任何云盘命令都有类似如下日志输出 如何登出和下线客户端 阿里云盘单账户最多只允许同时登录 10 台设备 当出现这个提示:你账号已超出最大登录设备数量,请先下线台设备,然后重启本应用,才可以继续使用 说明你的账号登录客户端已经超过数量,你需要先登出其他客户端才能继续使用,如下所示
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值