WP7控件開發(一)
一、UIElement控件通用屬性
-Height/Width:使用者設定的控件大小,是預期的大小
-ActualHeight/ActualWidth:擷取控件的實際大小
-MaxHeight/MaxWidth & MinHeight/MinWidth :設定控件大小的三個屬性()如果值發生沖突,首先要保證的是Min然後是Max,但是這兩個值一定要在Height/Width設定值之間才有效
-Cursor:設定/擷取控件光标形狀
-DataContext:設定或擷取控件資料内容
-HorizontalAlignment/VerticalAlignment:設定/擷取控件水準/垂直方向的對其方式
-Language:設定/擷取localization/globalization語言資訊
-Margin:設定/擷取控件與頁面的邊距
-Name:設定/擷取控件的名稱
-Parent:設定擷取控件的父容器
-Resource:設定/擷取控件資源字典,使資源像樣式那樣通過引用資源竄名,在Xaml中使用
-Style:設定/或擷取控件的外觀樣式,也可以先定義好綁定到多個控件上
-Tag:為控件添加标簽說明
-CacheMOde:設定/擷取一個值,該值訓示應在可能高速緩存已呈現的内容
-Clip:設定/擷取控件剪裁效果
-DesireSize:擷取系統布局大小,對于布局的調整很有用
-Opacity:設定/擷取控件的透明度
-OpacityMask:設定/擷取一個控件蒙版,來産生蒙版透明效果
-UseLayoutRounding:設定/擷取控件及子控件是否按子像素進行布局,使控件外觀圓滑清晰
-Visiblity:設定/擷取控件是否可見
-Background:設定/擷取控件的背景效果
-Projection:設定/擷取控件的3-D透視效果
-Foreground:設定/擷取字型顔色
-RenderTransformOrigin:設定/擷取變形的起始點
-RenderTransform:設定/擷取變形效果
-Template:設定或擷取控件模闆
-IsHitTestVisible:擷取或設定控件是否接受焦點事件
-HorizontalContentsAlignment/VerticalContentsAligment:擷取或設定控件内容的對齊方式
二、容器控件(Grid,Canvas,StackPanel,Border,PopUp,ScrollView)
1、Grid的使用
2、Canvas的使用:用來精确定位容器内的控件坐标,以及層次關系
3、StackPanel使用:設定控件的排列順序
4、Border使用:可以容納其它控件
5、PopUp:自身可以被打開和關閉,通常用來制作自定義的消息彈出框和輸入框
7、ScrollView:拖動顯示其包含的子控件的内容
三、按鈕控件的使用(Button,HyperlinkButton,RepeatButton,ToggleButton)
1、HyperlinkButton:用于連接配接本地或Web位址,當連結Web位址時,一定要在在标簽裡加上TargetName=“_Self”的屬性值
2、RepeatButton:按下後不斷觸發Click事件
3、ToggleButton:開關按鈕,三種狀态Checked、Unchecked、Indeterminate
控件開發(二)
1、PasswordBox:用于輸入自定義遮罩字元的密碼框控件,屬性PasswordChar用來顯示輸入的密碼替換符号
2、TextBox:可以讓軟鍵盤産生不同的鍵面效果;InputScope屬性可通過代碼擷取屬性清單
typeof(InputScopeNameValue).GetFields(BindingFlags.Public|BindingFlags.Static)
3、Image控件:隻能加載png和jpg的圖檔
4、MediaElement:播放本地或網絡上的多媒體;支援多媒體格式:WAV、MP3,支援mms、rtspt、rtsp流媒體協定;-屬性IsMuted是否靜音Stretch設定視訊畫面在控件中的填充方式AutoPlay是否自動播放;-事件MediaOpened MediaEnded MediaFailed 注意:其對視訊的格式和幀大小有相應的要求
5、TextBlack:在頁面上顯示文字
6、CheckBox:多選控件;不能通過Width和Height來改變大小;可以通過其屬性RenderTransform的ScaleTransform(ScaleX、ScaleY)變形改變大小
7、RadioButton:單選按鈕;其改變大小的方式同CheckBox
8、ProgressBar:兩種類型:顯示确切進度和不斷重複的動畫
9、Slider:可以設定水準、垂直方向的滑竿
10、Thumb:通過拖動,擷取連續的坐标,三個基本事件DragDelta(滑鼠移動時)、DragStart(開始拖動)、DragComplete(拖動完成)
11、ListBox:相當一個容器,可以通過ListItem來組合多個控件而得到不同功能的List
控件開發(三)-繪圖控件,地圖控件
-InkPresenter:産生手寫效果
示例代碼:
Stroke newStroke;
private void inkPresenter1_LostMouseCapture(object sender, MouseEventArgs e)
{
newStroke = null;//失去焦點時銷毀上一次的Stroke
}
private void inkPresenter1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
inkPresenter1.CaptureMouse();//開始捕獲滑鼠移動路徑
StylusPointCollection spc = new StylusPointCollection();
spc.Add(e.StylusDevice.GetStylusPoints(inkPresenter1));
newStroke = new Stroke();
this.inkPresenter1.Strokes.Add(newStroke);
}
private void inkPresenter1_MouseMove(object sender, MouseEventArgs e)
{
if (newStroke != null)
{
//記錄滑鼠在inkPresenter1上的移動的點
newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkPresenter1));
}
}
-Path:通過Markup Syntax來繪制一系列的線條,通過Geometries來繪制形狀
示例:
<Path Height="428" HorizontalAlignment="Left"
Margin="12,127,0,0" Name="path1" Stroke="Red" StrokeThickness="10" VerticalAlignment="Top" Width="456" Fill="Green">
<Path.Data>
<EllipseGeometry Center="200,200" RadiusX="100" RadiusY="30"/>
</Path.Data>
</Path>
-Ellipse:繪制圓形或橢圓形
-Rectangle:繪制矩形
-Line:繪制兩點間的連線
-Polygon:繪制封閉多邊形
-Polyline:繪制封閉、開發多邊形
-Glyphs:繪制字母、符号、字元等,主要用來顯示Unicode字元,需要加載字型庫從網上下載下傳字型庫,對于 使用不多的情況使用,否則會消耗系統的資源
-Map控件:在使用時,首先要申請授權驗證密鑰 顯示模式設定有Road、Arial
-顯示縮放按鈕:ZoomBarVisibility屬性
-顯示比例尺:ScaleVisibility屬性
-加标記:用到Pushpin類
//為地圖加标記
Pushpin pin = new Pushpin();
pin.Location = new GeoCoordinate(30.3441333,120.342155132);
pin.Width = 200;
pin.Height = 200;
pin.Content = "濟南";
pin.Background = new SolidColorBrush(Colors.Red);
mymap.Children.Add(pin);
-繪制多變型區域:用到MapPolygon類 執行個體化 設定Locations屬性即可
//在地圖上繪制多邊形
MapPolygon polygon = new MapPolygon();
polygon.Fill = new SolidColorBrush(Colors.Red);
polygon.Stroke = new SolidColorBrush(Colors.Yellow);
polygon.StrokeThickness = 5;
polygon.Opacity = 0.7;
polygon.Locations = new LocationCollection()
{
new GeoCoordinate(30,120),
new GeoCoordinate(30,130),
new GeoCoordinate(30,160),
new GeoCoordinate(30,140)
};
mymap.Children.Add(polygon);
-繪制多邊線:用到MapPolyline 執行個體化 設定Stroke屬性和Locatatoins
//在地圖上繪制多邊線
MapPolyline polyline = new MapPolyline();
polyline.Stroke = new SolidColorBrush(Colors.Red);
polyline.StrokeThickness = 5;
polyline.Opacity = 0.5;
polyline.Locations = new LocationCollection()
{
new GeoCoordinate(30.3424242,120.3432444),
new GeoCoordinate(30.3424242,120.3432444)
};
mymap.Children.Add(polyline);
-在地圖上添加圖檔
//在地圖上添加圖檔
Image image = new Image();
image.Width = 100;
image.Height = 100;
image.Source = new BitmapImage(new Uri("Images/Pic1.jpg",UriKind.Relative));
MapLayer imagelayer = new MapLayer();
imagelayer.AddChild(image,new GeoCoordinate(30,120),PositionOrigin.BottomLeft);
mymap.Children.Add(imagelayer);
WP7控件開發(四)-Silverlight Tookit控件集
包括:Contextmenu、ToggleSwitch、WrapPanel、DatePicker、TimePicker、AutoCompleteBox、NavigationTransition、ListPicker、LongListSelector
-Contextmenu
-長按彈出菜單
-不能在容器控件中使用
-ToggleSwitch:具有兩種狀态Checked和Unchecked
-WrapPanel:用來對大量控件進行按順序排列的容器
-DatePicker:設定日期時間,可通過ValueStringFormat來設定時間的顯示格式:{}{0:d},{}{0:t} ,{}{0:D},{}{0:T},{}{0:MM-dd-yyyy},{}{0:HH:mm}
-TimePicker:設定時間時分秒
-AutoCompleteBox:
屬性:
-FilterMode:比對方式
-IsDropDownOpen:下拉清單是否打開
-IsTextCompletionEnable:自動完成比對填寫
-MaxDropDownHeight:下拉清單的最大高度
-MinimumPopulateDelay:最小比對時間
-MinimumPrefixLength:最短比對長度
事件:
-DropDownClosed
-DropDownClosing
-DropDownOpened
-DropDownOpening
-NavigationTransition:
-實作頁面的切換效果
-使用之前要将App.xaml.cs中InitializePhoneAppliation()函數裡的RootFrame進行修改
如:RootFrame=new TransitionFrame();
-五種動畫效果包括:RollTransition、RotateTransition、SlideTransition、 SwiveTranstion、TurnstileTransition
示例:
<toolkit:TransitionService.NavigationInTransition> //進入頁面動畫效果
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:RotateTransition Mode="In180Clockwise"/>//這是一個旋轉的動畫效果
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:RotateTransition Mode="In180Clockwise"/>
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<toolkit:TransitionService.NavigationOutTransition> //退出頁面動畫效果
<toolkit:NavigationOutTransition>
<toolkit:NavigationOutTransition.Backward>//後退的動畫效果
<toolkit:RotateTransition Mode="Out180Clockwise"/>
</toolkit:NavigationOutTransition.Backward>
<toolkit:NavigationOutTransition.Forward>
<toolkit:RotateTransition Mode="Out180Clockwise"/>
</toolkit:NavigationOutTransition.Forward>//向前的動畫效果
</toolkit:NavigationOutTransition>
</toolkit:TransitionService.NavigationOutTransition>
-ListPicker:簡單的清單框,Full Mode完整頁面的清單
-LongLIstSelector:資料歸類清單,把資料進行綁定和分類
-UserControl:使用者自定義控件,UserControl類,同樣繼承于UIElement
示例:Waiting控件的實作
WP7控件開發(五)-Panorama全景視圖,Pivot樞軸視圖
-Panorama視圖:使用一個超過螢幕寬度的長水準畫布,提供獨特顯示控件,資料和服務的方式,是一種選項、導航和資料的多螢幕 滾動菜單
-結構包括:Background,Title,Items,Background圖檔高度要為800像素,寬度大于480像素,小于2000像素
-Pivot視圖:快捷管理應用中的視圖或頁面,過濾資料,視圖分類
-結構包括:Title,Header,PivotItem
-使用注意:Header文字不要顯示過長,以免其他PivotItem中的Header無法顯示,在PivotItem中,不要使用ScrollViewer 或ListBox這類帶有手勢的控件
WP7控件開發(六)-DeepZoom技術
-DeepZoom:源于遙感影像的金字塔顯示方式,提供了與高分辨率圖像進行互動的能力,可以快速縮放圖像而不影響應用的性能,加載或平移圖像時可以光滑過度
-應用:高分辨率、極大圖像的浏覽,3D合成圖像,廣告宣傳
-分類:Single和Collection
-DeepZoom Composer制作工具下載下傳位址:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=457B17B7-52BF-4BDA-
87A3-FA8A4673F8BF
-MulitScaleImage:打開、放大和平移多分辨率圖像,快速任意縮放展示大圖形、高分辨率圖像的應用程式 -屬性:Source,UseSprings-springs animations,ViewportOrigin-CenterPoint,ViewportWidth-ZoomLevel