Windows Phone 7Silverlight控件之--Panorama
Silverlight for Windows Phone 7的Pivot、Panorama控件是一個類似于Android應用程序列表中可以翻頁控件,具有如下特點
1.簡單的XAML和編程接口
2.完全支持數據綁定、內容模板屬性和項目容器樣式
3.內置黑、白兩種皮膚樣式
4.內置觸控導航,可以讓用戶快速滑動控件并定位到指定的項
5.在頁面或內容項導航滑動時,提供漂亮的過渡動畫
6.強大的可擴展性,用戶可通過事件、可視化狀態和重新定義模板的方式擴展功能。
?
今天這一講是Panorama的如何使用
一、重要屬性和方法
1.說明
Panorama提供了可以創建翻頁的全景視圖。
2.重要屬性
public object DefaultItem:獲取或設置Panorama的默認Item
SelectedIndex:獲取或設置被選中的PanoramaItem的索引
SelectedItem:獲取或設置被選中的PanoramatItem
Title:獲取或設置Panorama的標題
3.重要方法
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e):當Panorama的Items集合改變時,通知Panorama更新Items的Header。
?
二、應用
1.新建項目
圖1和圖2兩種方法
圖1
?
圖2
使用圖2方法新建后VS將自動產生Panorama項目模板,這種方法比較簡單。如下圖
圖3
2.圖1步驟
從工具箱中拖Panorama控件到視圖工作區,在本例中一共有四頁,第一頁是一個ListBox控件,第二頁是一個Ellipse控件,第三頁是一個多行文本區域控件(TextBlock),第四頁是一個具有動畫效果的文本,我們可以通過左右滑動來進行換頁,大家或許已經看出它和Pivot的差別,在一頁中它可以看到部分屬于第二頁的東東,而且它的標題Title橫跨整個Panorama布局
?? <controls:Panorama Title="panorama 演示" x:Name="panorama">
??????????????? <controls:PanoramaItem Header="ListBox">
??????????????????? <ListBox FontSize="{StaticResource PhoneFontSizeLarge}">
??????????????????????? <ListBox.ItemTemplate>
??????????????????????????? <DataTemplate>
??????????????????????????????? <TextBlock Text="{Binding}"
?????????????????????????????????? FontFamily="{Binding}" />
??????????????????????????? </DataTemplate>
??????????????????????? </ListBox.ItemTemplate>
??????????????????????? <system:String>Arial</system:String>
??????????????????????? <system:String>Arial Black</system:String>
??????????????????????? <system:String>Calibri</system:String>
??????????????????????? <system:String>Comic Sans MS</system:String>
??????????????????????? <system:String>Courier New</system:String>
??????????????????????? <system:String>Georgia</system:String>
??????????????????????? <system:String>Lucida Sans Unicode</system:String>
??????????????????????? <system:String>Portable User Interface</system:String>
??????????????????????? <system:String>Segoe WP</system:String>
??????????????????????? <system:String>Segoe WP Black</system:String>
??????????????????????? <system:String>Segoe WP Bold</system:String>
??????????????????????? <system:String>Segoe WP Light</system:String>
??????????????????????? <system:String>Segoe WP Semibold</system:String>
??????????????????????? <system:String>Segoe WP SemiLight</system:String>
??????????????????????? <system:String>Tahoma</system:String>
??????????????????????? <system:String>Times New Roman</system:String>
??????????????????????? <system:String>Trebuchet MS</system:String>
??????????????????????? <system:String>Verdana</system:String>
??????????????????????? <system:String>Webdings</system:String>
??????????????????? </ListBox>
??????????????? </controls:PanoramaItem>
??????????????? <controls:PanoramaItem Header="Ellipse">
??????????????????? <Ellipse>
??????????????????????? <Ellipse.Fill>
??????????????????????????? <LinearGradientBrush>
??????????????????????????????? <GradientStop Offset="0" Color="{StaticResource PhoneAccentColor}" />
??????????????????????????????? <GradientStop Offset="0.5" Color="{StaticResource PhoneBackgroundColor}" />
??????????????????????????????? <GradientStop Offset="1" Color="{StaticResource PhoneForegroundColor}" />
??????????????????????????? </LinearGradientBrush>
??????????????????????? </Ellipse.Fill>
??????????????????? </Ellipse>
??????????????? </controls:PanoramaItem>
??????????????? <controls:PanoramaItem Header="TextBlock">
??????????????????? <ScrollViewer>
???????????????????
??????????????????????? <TextBlock TextWrapping="Wrap">
??????????????????? For a long time I used to go to bed early. Sometimes, when I had put out
??????????????????? my candle, my eyes would close so quickly that I had not even time to
??????????????????? say "I'm going to sleep." And half an hour later the thought that it was
??????????????????? time to go to sleep would awaken me; I would try to put away the book
??????????????????? which, I imagined, was still in my hands, and to blow out the light; I
??????????????????? had been thinking all the time, while I was asleep, of what I had just
??????????????????? been reading, but my thoughts had run into a channel of their own,
??????????????????? until I myself seemed actually to have become the subject of my book:
??????????????????? a church, a quartet, the rivalry between Fran?ois I and Charles V. This
??????????????????? impression would persist for some moments after I was awake; it did not
??????????????????? disturb my mind, but it lay like scales upon my eyes and prevented them
??????????????????? from registering the fact that the candle was no longer burning. Then
??????????????????? it would begin to seem unintelligible, as the thoughts of a former
??????????????????? existence must be to a reincarnate spirit; the subject of my book would
??????????????????? separate itself from me, leaving me free to choose whether I would form
??????????????????? part of it or no; and at the same time my sight would return and I
??????????????????? would be astonished to find myself in a state of darkness, pleasant and
??????????????????? restful enough for the eyes, and even more, perhaps, for my mind, to
??????????????????? which it appeared incomprehensible, without a cause, a matter dark
??????????????????? indeed.
??????????????????????? </TextBlock>
??????????????????? </ScrollViewer>
??????????????? </controls:PanoramaItem>
??????????????? <controls:PanoramaItem Header="Animation">
??????????????????? <TextBlock Text="Hello, Windows Phone 7!"
?????????????????????? HorizontalAlignment="Left"
?????????????????????? VerticalAlignment="Top"
?????????????????????? RenderTransformOrigin="0.5 0.5">
??????????????? <TextBlock.RenderTransform>
??????????????????? <CompositeTransform x:Name="xform" />
??????????????? </TextBlock.RenderTransform>
??????????????????? </TextBlock>
??????????????????? <controls:PanoramaItem.Triggers>
??????????????????????? <EventTrigger>
??????????????????????????? <BeginStoryboard>
??????????????????????????????? <Storyboard>
??????????????????????????????????? <DoubleAnimation Storyboard.TargetName="xform"
???????????????????????????????????????????? Storyboard.TargetProperty="Rotation"
???????????????????????????????????????????? From="0" To="360" Duration="0:0:3"
???????????????????????????????????????????? RepeatBehavior="Forever" />
??????????????????????????????????? <DoubleAnimation Storyboard.TargetName="xform"
???????????????????????????????????????????? Storyboard.TargetProperty="TranslateX"
???????????????????????????????????????????? From="0" To="300" Duration="0:0:5"
???????????????????????????????????????????? AutoReverse="True"
???????????????????????????????????????????? RepeatBehavior="Forever" />
??????????????????????????????????? <DoubleAnimation Storyboard.TargetName="xform"
???????????????????????????????????????????? Storyboard.TargetProperty="TranslateY"
???????????????????????????????????????????? From="0" To="600" Duration="0:0:7"
???????????????????????????????????????????? AutoReverse="True"
???????????????????????????????????????????? RepeatBehavior="Forever" />
??????????????????????????????? </Storyboard>
??????????????????????????? </BeginStoryboard>
??????????????????????? </EventTrigger>
??????????????????? </controls:PanoramaItem.Triggers>
??????????????? </controls:PanoramaItem>
??????????? </controls:Panorama>
效果如圖
?
3.數據綁定
1)數據源類Datas.cs
??? public static class Datas
??? {
??????? public static List<string> GetDatas()
??????? {
??????????? List<string> list = new List<string>();
??????????? list.Add("salam");
??????????? list.Add("Aiming Zhang");
??????????? return list;
??????? }
??? }
?
2)MainPage.cs
? public partial class MainPage : PhoneApplicationPage
??? {
??????? // Constructor
??????? public MainPage()
??????? {
??????????? InitializeComponent();
??????????? this.panorama.ItemsSource = Datas.GetDatas();
??????? }
??? }
效果如圖
?
總結
以上是生活随笔為你收集整理的Windows Phone 7Silverlight控件之--Panorama的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用ADO.NET的ExecuteScal
- 下一篇: 操作系统和数据库的知识梳理(思维导图)