【www.bbyears.com--Silverlight】
Silverlight应用程序默认运行在竖屏模式下,当手机改变方向时,如果想让我们的应用程序可以随着方向的改变自动作出响应,只需要在MainPage.xaml的PhoneApplicationPage标记中将属性SupportedOritentations的值修改就可以了,它的值是枚举类型,值为Portrait,Landscape或PortraitOrLandscape。
处理动态布局时最重要的两个属性是HorizontalAlignment和VerticalAlignment。下面是一个例子,它将9个TextBlock元素放在一个Grid元素中,以展示Grid的HorizontalAlignment和VerticalAlignment在9种不同组合下的用法。
xaml文件
代码如下
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
效果如图:
竖直方向 水平方向
在Silverlight的布局系统中,Margin(外边距)属性也非常重要,Margin属性是Thickness类型的,Thickness是一个有Left,Top,Right,Bottom四个属性的结构体,一般情况下我们都会指定四个数值,分别表示左,上,右,下边距。当然在XAML中也可以指定一个数值,它表示四个边距都为这个值,如果指定2个数值,那么它们分别代表距左右,上下的边距。下面例子给上面程序中第5个TextBlock添加Margin属性。
XAML代码:
代码如下效果如图:
我们可以看到,Text为Center的TextBlock不再居中了。
以上就是今天总结的内容,主要有三个重要属性,分别是HorzontalAlignment,VerticalAlignment和Margin。在实际的应用中,我们要灵活运用这三个属性。
<script type="text/javascript"> if ($ != jQuery) { $ = jQuery.noConflict(); } var isLogined = true; var cb_blogId = 96589; var cb_entryId = 2340598; var cb_blogApp = "mcgrady"; var cb_blogUserGuid = "0e6193ca-86a1-e011-a53f-842b2b196315"; var cb_entryCreatedDate = "2012/2/6 21:32:00"; </script>