[Winodows Phone 7控件详解]控件基础
????? Windows Phone7提供了豐富的silverlight控件,但是和silverlight又有一定的區別的,其中有很多控件都是不可用的,另外有些控件即使可以用,但有一些屬性也是不可用的。后面將一一介紹各個控件的基本使用方法和一些特別的屬性用法。
????Windows Phone7控件限制多多啊,這里兩個列表說明了WP7版本可用和不用控件,WP7.1新增控件和Silverlight Toolkit for Windows Phone控件包新增控件后面后面講述。
可用控件:
不可用控件:
不過這些控件隨然不能用了,但是有一些還是可以用其他控件來替代的,比如:
Label:被TextBlock取代了。????
ScrollBar:被ScrollView取代了。
還有一些控件需要自定義了,比如ComboBox等。
?
對于這些可用控件,基本上都有一些通用的屬性:
Height/Width:用戶設置的控件大小,是預期的大小。
ActualHeight/ActualWidth: 只讀,控件的實際大小。(注意和Height/Width區別)
Cursor:設置/獲取控件光標形狀。
DataContext:設置/獲取控件綁定數據。
HorizontalAlignment/VerticalAlignment:設置/獲取控件水平/垂直方向的對齊方式。
Language:設置/獲取localization/globalization語言信息,如Language=”en-US”
Margin:設置/獲取控件與頁面的邊距。
MaxHeight/MaxWidth &? MinHeight/MinWidth:設置控件大小的三個屬性(還有Height/Width)中的兩個。如果三個值發生沖突,首先要保證的是Min然后是Max,但是這兩個值一定要在Height/Width設置值之間才有效。
Name:設置/獲取控件的名稱。
Parent:只讀,獲取控件的父對象。
Resources:設置/獲取控件資源字典,使資源像樣式一樣通過引用資源串名,在XAML中使用。資源可以是任何數據類型。(*)
Style:設置/獲取控件的外觀樣式,也可以先定義好后,綁定到多個控件上。
Tag:為控件加標簽說明。
CacheMode:設置/獲取一個值,該值指示應在可能時高速緩存已呈現內容。如:
<Image.CacheMode><!-- 緩存--><BitmapCache RenderAtScale="8"/>
</Image.CacheMode>
Clip:設置/獲取控件剪裁效果。如:
<Image.Clip><!-- 裁剪--><RectangleGeometry Rect="50, 50, 370,480" RadiusX="20" RadiusY="20"/>
</Image.Clip>
DesiredSize:獲取系統布面大小,對于布局的調整很有用。
Opacity:設置/獲取控件的透明度。
OpacityMask:設置/獲取一個控件蒙板,來產生蒙板透明效果。如:
<Image.OpacityMask> <!-- 產生蒙板透明效果--><RadialGradientBrush>
<GradientStop Color="#0C000000" Offset="1"/>
<GradientStop Color="White" Offset="0.3"/>
</RadialGradientBrush>
</Image.OpacityMask>
Projection:設置/獲取控件3-D透視效果。如:
<Image.Projection><!-- 獲取控件的3D透視效果--><PlaneProjection
LocalOffsetX ="-3" RotationX="49" RotationY="47" RotationZ="34" CenterOfRotationX="0" CenterOfRotationZ="-2.3" GlobalOffsetX="63" GlobalOffsetY="21"
GlobalOffsetZ="40"/>
</Image.Projection>
RenderTransform:設置/獲取控件變形效果,如:
<Image.RenderTransform><!-- 控件的呈現變換--><RotateTransform CenterX="100" CenterY="300" Angle="60"/>
</Image.RenderTransform>
RenderTransformOrigin:設置/獲取變形的起始點
UseLayoutRounding:設置/獲取控件及其子控件是否按子像素進行布局,這可以使控件外觀圓滑清晰。
Visibility:設置/獲取控件是否可見。
Background:設置/獲取控件背景效果。
BorderBrush:設置/獲取控件邊框效果。
BorderThickness:設置/獲取控件邊框粗細。
FontFamily:設置/獲取字體。
FontSize: 設置/獲取字體大小。
FontStretch: 設置/獲取字體字形。
FontStyle: 設置/獲取字體樣式。
FontWeight: 設置/獲取字體粗細。
Foreground: 設置/獲取字體顏色。
IsEnabled:設置/獲取控件是否可用。如果為false,控件無法獲取焦點,不能輸入。
IsTabStop:設置/獲取控件是否加入TabNavigation;如果為false, 控件無法獲取輸入焦點。
Padding: 設置/獲取控件與容器的邊距。
TabIndex:設置/獲取控件獲取焦點的順序。
TabNavigation:設置/獲取控件焦點順序按什么方式輪轉。
Template:設置/獲取控件模板。如:
<PasswordBox Height="72" HorizontalAlignment="Left" Margin="14,76,0,0" Name="passwordBox1" VerticalAlignment="Top" Width="460" ><PasswordBox.Template>
<ControlTemplate>
<Border BorderThickness="5" Background="Red" BorderBrush="Yellow"/>
</ControlTemplate>
</PasswordBox.Template>
</PasswordBox>
HorizontalContentsAligment/VerticalContentsAlignment:設置/獲取控件內容的對齊方式。
IsHitTestVisible:設置/獲取控件是否接收輸入事件,如mouse事件等;如果為false,無法獲得焦點。
?
下面給出一個綜合示例:
MainPage.xaml代碼:
View Code <phone:PhoneApplicationPagex:Class="控件開發.MainPage"
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="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Height="607" Margin="0,0,-12,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Source="Images/1.jpg">
<Image.CacheMode><!-- 緩存-->
<BitmapCache RenderAtScale="8"/>
</Image.CacheMode>
<Image.Clip><!-- 裁剪-->
<RectangleGeometry Rect="50, 50, 370,480" RadiusX="20" RadiusY="20"/>
</Image.Clip>
<Image.Opacity > <!-- 透明度-->
1
</Image.Opacity>
<Image.OpacityMask> <!-- 產生蒙板透明效果-->
<RadialGradientBrush>
<GradientStop Color="#0C000000" Offset="1"/>
<GradientStop Color="White" Offset="0.3"/>
</RadialGradientBrush>
</Image.OpacityMask>
<Image.Projection><!-- 獲取控件的3D透視效果-->
<PlaneProjection
LocalOffsetX ="-3" RotationX="49" RotationY="47" RotationZ="34" CenterOfRotationX="0" CenterOfRotationZ="-2.3" GlobalOffsetX="63" GlobalOffsetY="21"
GlobalOffsetZ="40"/>
</Image.Projection>
<Image.RenderTransform><!-- 控件的呈現變換-->
<RotateTransform CenterX="100" CenterY="300" Angle="60"/>
</Image.RenderTransform>
</Image>
</Grid>
</Grid>
<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
</phone:PhoneApplicationPage>
未加入MainPage.xaml.cs特殊邏輯
程序運行效果如下:
總結
以上是生活随笔為你收集整理的[Winodows Phone 7控件详解]控件基础的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2022 年西安新能源汽车产量居全国第一
- 下一篇: 华米上架 Amazfit Falcon