自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows Phone開發(fā)(12):認識一下獨具個性的磁貼

移動開發(fā)
Windows Phone是微軟發(fā)布的一款手機操作系統(tǒng),它將微軟旗下的Xbox Live游戲、Xbox Music音樂與獨特的視頻體驗整合至手機中。

對“磁貼”的理解是一點也不抽象的,為什么呢?只要你愿意啟動WP系統(tǒng),無論你是在模擬器中還是在真機中,是的,桌面上那一塊塊像地板的玩意兒,就是磁貼了。
(圖:磁貼)

在上圖中,我們很直觀地看到磁貼圖塊的“真”面目,呵呵,其實很明顯,這個設計真的很有個性,老實說,WP剛推出的時候,很多人說它這個那個的,其實這些人只過是起起哄罷了。
我是挺喜歡桌面上那一塊塊的圖塊的,這也是WP第一次給我留下的深刻印象,畢竟在安卓和IOS上,我們看到的都是傳統(tǒng)手機的圖標顯示方式,而WP總讓我覺得很有個性。

好的,看完了整體的,我們來看看局部的,好嗎?別小看這些正方形的圖塊,里面可是大有文章的哦。不信?一起去瞧瞧。

磁貼的一個圖塊基本上由三個元素組成——背景圖,標題文字以及計數(shù)器,嗯,當然了,圖塊最有意思的地方,就是它有正反兩面。
下圖為圖塊正反兩面的元素組成結構圖。


磁貼的分類。

磁貼分為應用程序磁貼和次要磁貼。
好不好理解呢?好,首先我們看看應用程序磁貼,它是指通過用戶應用程序列表中長按應用程序來把應用程序固定到“開始”屏幕。

那么,如何刪除呢?在“開始”屏幕上找到你要移除的圖塊,長按,圖塊左上角會出現(xiàn)一個小圖標,我們點擊這小圖標即可移除該磁貼。當然了,如果你想把移動到其它位置,在此時,你只需把圖標拖到對應的位置,然后在桌面上隨便點一下即可完成移動操作。


次要磁貼就是相對于剛才的上面的應用程序磁貼而言的,它是由應用程序通過特定參數(shù)創(chuàng)建的,說直接一點嘛,就是通過我們開發(fā)者,用代碼來創(chuàng)建的。

這個好比我們Windows桌面上的快捷方式,有的是直接指向可執(zhí)行程序的,而有的是應用程序創(chuàng)建的,它后面帶了命令行參數(shù)。舉個例子吧,最典型的 要數(shù)IE了,我經(jīng)常上新浪微博,我希望在桌面上創(chuàng)建一個IE的快捷方式圖標,雙擊運行IE的時候新打開新浪微博主頁,那怎么做呢?請看下圖。


這樣一來,你雙擊快捷方式啟動IE就自動打開新浪微博首頁。呵呵,次要磁貼也和這相類似。

動手實戰(zhàn)。

下面,我們一起來動手做一個稍微綜合一點的例子,嗯,現(xiàn)在,你可以坐下來,先喝幾口奶茶,然后啟動VS,新建一個WP項目。 界面布局大致如下,你可以自由發(fā)揮。

準備好兩張美圖,圖片內(nèi)容你喜歡,但要鍵康哦,尺寸為173*173像素,.jpg或.png都行,一張作為磁貼的正面背景,另一張作為磁貼的背面背景。
注意:把圖片的生成操作改為“內(nèi)容”。

別走開,下頁為您提供具體代碼

#p#

當然,為了方便大家練習參考,我把XAML貼出來,希望大家不要直接復制,而是認認真真的在VS里面輸一遍,要多寫代碼多練習才會找到感覺的哦。

  1. <phone:PhoneApplicationPage  
  2.     x:Class="ShellTitleApp.MainPage" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  11.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  12.     Foreground="{StaticResource PhoneForegroundBrush}" 
  13.     SupportedOrientations="Portrait" Orientation="Portrait" 
  14.     shell:SystemTray.IsVisible="True"
  15.      
  16.     <phone:PhoneApplicationPage.Resources> 
  17.         <Style x:Key="textblStyle" TargetType="TextBlock"
  18.             <Setter Property="FontSize" Value="28"/> 
  19.             <Setter Property="Margin" Value="0,12,5,6"/> 
  20.             <Setter Property="HorizontalAlignment" Value="Right"/> 
  21.         </Style> 
  22.         <Style x:Key="textboxStyle" TargetType="TextBox"
  23.             <Setter Property="FontSize" Value="28"/> 
  24.             <Setter Property="Width" Value="300"/> 
  25.             <Setter Property="Height" Value="auto"/> 
  26.             <Setter Property="HorizontalAlignment" Value="Left"/> 
  27.         </Style> 
  28.     </phone:PhoneApplicationPage.Resources> 
  29.  
  30.     <!--LayoutRoot 是包含所有頁面內(nèi)容的根網(wǎng)格--> 
  31.     <Grid x:Name="LayoutRoot" Background="Transparent"
  32.         <Grid.RowDefinitions> 
  33.             <RowDefinition Height="Auto"/> 
  34.             <RowDefinition Height="*"/> 
  35.         </Grid.RowDefinitions> 
  36.  
  37.         <!--TitlePanel 包含應用程序的名稱和頁標題--> 
  38.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"
  39.             <TextBlock x:Name="ApplicationTitle" Text="我的應用程序" Style="{StaticResource PhoneTextNormalStyle}"/> 
  40.             <TextBlock x:Name="PageTitle" Text="示例程序" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
  41.         </StackPanel> 
  42.  
  43.         <!--ContentPanel - 在此處放置其他內(nèi)容--> 
  44.         <Grid x:Name="ContentPanel" Margin="0" Grid.Row="1"
  45.             <Grid.RowDefinitions> 
  46.                 <RowDefinition Height="*" /> 
  47.                 <RowDefinition Height="auto" /> 
  48.             </Grid.RowDefinitions> 
  49.             <ScrollViewer HorizontalScrollBarVisibility="Auto" Grid.Row="0"
  50.                 <Grid Margin="1"
  51.                     <Grid.RowDefinitions> 
  52.                         <RowDefinition Height="auto"/> 
  53.                         <RowDefinition Height="auto"/> 
  54.                         <RowDefinition Height="auto"/> 
  55.                         <RowDefinition Height="auto"/> 
  56.                         <RowDefinition Height="auto"/> 
  57.                     </Grid.RowDefinitions> 
  58.                     <Grid.ColumnDefinitions> 
  59.                         <ColumnDefinition Width="auto"/> 
  60.                         <ColumnDefinition Width="*"/> 
  61.                     </Grid.ColumnDefinitions> 
  62.                     <TextBlock Grid.Row="0" 
  63.                                Grid.Column="0" 
  64.                                Text="正面標題:" Style="{StaticResource textblStyle}" /> 
  65.                     <TextBox x:Name="txtForeTitle" 
  66.                              Style="{StaticResource textboxStyle}" 
  67.                              Grid.Row="0" 
  68.                              Grid.Column="1"/> 
  69.                     <TextBlock Text="計數(shù)器:" Style="{StaticResource textblStyle}" 
  70.                                Grid.Row="1" 
  71.                                Grid.Column="0"/> 
  72.                     <TextBox x:Name="txtCount" 
  73.                              Grid.Column="1" 
  74.                              Grid.Row="1" Style="{StaticResource textboxStyle}" > 
  75.                         <!--只允許輸入數(shù)字--> 
  76.                         <TextBox.InputScope> 
  77.                             <InputScope > 
  78.                                 <InputScopeName NameValue="Number"/> 
  79.                             </InputScope> 
  80.                         </TextBox.InputScope> 
  81.                     </TextBox> 
  82.                     <TextBlock Text="背面標題:" 
  83.                                Grid.Row="2" 
  84.                                Grid.Column="0" Style="{StaticResource textblStyle}" /> 
  85.                     <TextBox x:Name="txtBackTitle" 
  86.                              Grid.Row="2" 
  87.                              Grid.Column="1" Style="{StaticResource textboxStyle}" /> 
  88.                     <TextBlock Text="背景內(nèi)容:" 
  89.                                Grid.Row="3" 
  90.                                Grid.Column="0" Style="{StaticResource textblStyle}" /> 
  91.                     <TextBox x:Name="txtBackContent" 
  92.                              Grid.Row="3" 
  93.                              Grid.Column="1" Style="{StaticResource textboxStyle}" /> 
  94.                     <!--提示是以何種方式啟動--> 
  95.                     <CheckBox x:Name="chkStartType" 
  96.                               IsChecked="False" 
  97.                               Grid.Row="4" 
  98.                               Grid.Column="0" 
  99.                               Grid.ColumnSpan="2" 
  100.                               FontSize="30" 
  101.                               Content="通過應用程序創(chuàng)建的磁貼啟動" IsEnabled="False" /> 
  102.                 </Grid> 
  103.             </ScrollViewer> 
  104.             <StackPanel Grid.Row="1" Orientation="Horizontal"
  105.                 <Button x:Name="btnAddToShellTitle" 
  106.                         Content="添加磁貼" Click="btnAddToShellTitle_Click" /> 
  107.                 <Button x:Name="btnUpdateShellTitle" 
  108.                         Content="更新" Click="btnUpdateShellTitle_Click" /> 
  109.                 <Button x:Name="btnDeleteShellTitle" 
  110.                         Content="刪除" Click="btnDeleteShellTitle_Click" /> 
  111.             </StackPanel> 
  112.         </Grid> 
  113.     </Grid> 
  114.  
  115. </phone:PhoneApplicationPage> 

好的,最后,當然是把C#代碼也寫完。

  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Net; 
  5. using System.Windows; 
  6. using System.Windows.Controls; 
  7. using System.Windows.Documents; 
  8. using System.Windows.Input; 
  9. using System.Windows.Media; 
  10. using System.Windows.Media.Animation; 
  11. using System.Windows.Shapes; 
  12. using Microsoft.Phone.Controls; 
  13. using Microsoft.Phone.Shell; 
  14. using System.Windows.Threading; 
  15. namespace ShellTitleApp 
  16.     public partial class MainPage : PhoneApplicationPage 
  17.     { 
  18.         // 要用的圖片的相對路徑 
  19.         private const string FORE_PIC = "images/a.png"
  20.         private const string BACK_PIC = "images/b.png"
  21.         // 構造函數(shù) 
  22.         public MainPage() 
  23.         { 
  24.             InitializeComponent(); 
  25.         } 
  26.         protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
  27.         { 
  28.             base.OnNavigatedTo(e); 
  29.             // 創(chuàng)建的磁貼的啟動地址其實是指向 /MainPage.xaml?s=1 
  30.             // s=1參數(shù)是為了區(qū)別用戶是不是通過程序所創(chuàng)建的磁貼來進入啟動當前程序的, 
  31.             // 就像面前例子中講到的把IE桌面快捷方式的參數(shù)指定為新浪微博的主頁一個道理。 
  32.  
  33.             // 檢測是否存在s=1來判斷是否通過程序創(chuàng)建的磁貼來啟動。 
  34.             ShellTile myTitle = ShellTile.ActiveTiles.FirstOrDefault(n => n.NavigationUri.ToString().Contains("s=1")); 
  35.             if (myTitle != null
  36.             { 
  37.                 this.chkStartType.IsChecked = true
  38.             } 
  39.             else 
  40.             { 
  41.                 this.chkStartType.IsChecked = false
  42.             } 
  43.         } 
  44.         // 創(chuàng)建圖塊 
  45.         private void btnAddToShellTitle_Click(object sender, RoutedEventArgs e) 
  46.         { 
  47.             // 不管我們的程序是否創(chuàng)建“開始”屏幕磁貼,ActiveTiles的第一個元素必是當前正在前臺運行的 
  48.             // 應用程序。所以,在取出第一個ShellTile時,一定要通過判斷是否存在s=1。 
  49.             // 這個s=1參數(shù)是隨便取的。 
  50.             ShellTile myTitle = ShellTile.ActiveTiles.FirstOrDefault(m => m.NavigationUri.ToString().Contains("s=1")); 
  51.             // 如果已經(jīng)創(chuàng)建就不建了。 
  52.             if (myTitle != null
  53.             { 
  54.                 MessageBox.Show("此應用程序的磁貼已經(jīng)存在。"); 
  55.             } 
  56.             else 
  57.             { 
  58.                 // 創(chuàng)建新磁貼 
  59.                 int Counter = 0; 
  60.                 // StandardTileData就是用來傳遞ShellTitle的屬性參數(shù)的, 
  61.                 // 如正面背景圖的URI,標題,計數(shù)器等。 
  62.                 StandardTileData myData = new StandardTileData() 
  63.                 { 
  64.                     Title = string.IsNullOrEmpty(txtForeTitle.Text) == true ? string.Empty : txtForeTitle.Text, 
  65.                     Count = int.TryParse(txtCount.Text, out Counter) == true ? Counter : 0, 
  66.                     BackTitle = string.IsNullOrEmpty(txtBackTitle.Text) == true ? string.Empty : txtBackTitle.Text, 
  67.                     BackContent = string.IsNullOrEmpty(txtBackContent.Text) == true ? string.Empty : txtBackContent.Text, 
  68.                     BackgroundImage = new Uri(FORE_PIC, UriKind.Relative), 
  69.                     BackBackgroundImage = new Uri(BACK_PIC, UriKind.Relative) 
  70.                 }; 
  71.  
  72.                 // ShellTile.Create方法的第一個參數(shù)是我們啟動應用程序時應該導航到哪里。 
  73.                 // 因為本示例主有一個頁面,當然是導航到主頁面, 
  74.                 // 因為是從我們創(chuàng)建的磁貼來啟動的,所以不要忘了帶上s=1參數(shù)。 
  75.                 ShellTile.Create(new Uri("/MainPage.xaml?s=1", UriKind.Relative), myData); 
  76.                 MessageBox.Show("磁貼圖塊創(chuàng)建成功。"); 
  77.             } 
  78.         } 
  79.         // 更新磁貼信息 
  80.         private void btnUpdateShellTitle_Click(object sender, RoutedEventArgs e) 
  81.         { 
  82.             // 同理,先要判斷是否從我們創(chuàng)建的磁貼啟動 
  83.             ShellTile myTitle = ShellTile.ActiveTiles.FirstOrDefault(m => m.NavigationUri.ToString().Contains("s=1")); 
  84.             if (myTitle != null
  85.             { 
  86.                 int Counter = 0; 
  87.                 StandardTileData data = new StandardTileData(); 
  88.                 if (!string.IsNullOrEmpty(txtForeTitle.Text)) 
  89.                 { 
  90.                     data.Title = txtForeTitle.Text; 
  91.                 } 
  92.                 if (int.TryParse(txtCount.Text,out Counter)) 
  93.                 { 
  94.                     data.Count = Counter; 
  95.                 } 
  96.                 if (!string.IsNullOrEmpty(txtBackTitle.Text)) 
  97.                 { 
  98.                     data.BackTitle = txtBackTitle.Text; 
  99.                 } 
  100.                 if (!string.IsNullOrEmpty(txtBackContent.Text)) 
  101.                 { 
  102.                     data.BackContent = txtBackContent.Text; 
  103.                 } 
  104.                 myTitle.Update(data); 
  105.                 MessageBox.Show("磁貼數(shù)據(jù)更新完成。"); 
  106.             } 
  107.         } 
  108.         // 刪除磁貼 
  109.         // 注意:我們使用代碼只可刪除次要磁貼,也就是我們用代碼創(chuàng)建的, 
  110.         // 不要去刪除應用程序磁貼,即通過在應用程序項上長按創(chuàng)建的。 
  111.         private void btnDeleteShellTitle_Click(object sender, RoutedEventArgs e) 
  112.         { 
  113.             // 記著,要先判斷是否找到通過我們代碼創(chuàng)建的磁貼。 
  114.             ShellTile title = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("s=1")); 
  115.             if (title != null
  116.             { 
  117.                 title.Delete(); 
  118.                 MessageBox.Show("磁貼圖塊刪除成功。"); 
  119.             } 
  120.         } 
  121.     } 

示例中我們重點是使用了ShellTile類,它并不復雜,成員不多,大家多玩幾次就熟了。

運行之后,我們在“開始”屏幕中創(chuàng)建我們的磁貼,然后回到桌面,我們盯著它別動,你會發(fā)現(xiàn),它的正面與反面會每隔幾秒鐘自動輪回切換。

責任編輯:閆佳明 來源: oschina
相關推薦

2022-12-07 08:13:55

CNI抽象接口

2013-02-19 09:04:32

Windows 8開發(fā)

2019-11-28 10:40:45

Kafka架構KafkaConsum

2023-05-03 09:09:28

Golang數(shù)組

2022-09-08 13:58:39

Spring高并發(fā)異步

2023-05-29 08:32:40

JAVA重寫重載

2018-12-24 09:51:22

CPU天梯圖Inter

2024-05-27 00:00:00

AmpPHP非阻塞

2013-04-25 14:15:53

Windows PhoWindows PhoWindows Pho

2018-04-02 09:07:36

CIO

2020-03-27 18:00:37

微軟Windows 10操作系統(tǒng)

2020-10-15 07:13:53

算法監(jiān)控數(shù)據(jù)

2021-06-16 09:49:14

Windows 11微軟動態(tài)磁貼

2010-04-12 17:32:59

Windows Pho

2013-04-17 11:10:02

Windows PhoWindows Pho

2020-09-25 19:53:39

數(shù)據(jù)

2020-04-26 09:59:00

黑客機器學習網(wǎng)絡安全

2015-12-21 10:49:57

Windows 10開始菜單磁貼

2013-07-30 12:37:56

Windows PhoWindows Pho

2022-01-19 09:37:29

微軟Windows11Windows
點贊
收藏

51CTO技術棧公眾號