具体的理论就不说了,直接来实践吧,先看代码:
首先是前台UI代码:
View Code
1 <phone:PhoneApplicationPage 2 x:Class="tubiao1.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 <!--LayoutRoot 是包含所有页面内容的根网格--> 17 <Grid x:Name="LayoutRoot" Background="Transparent"> 18 <Grid.RowDefinitions> 19 <RowDefinition Height="Auto"/> 20 <RowDefinition Height="*"/> 21 </Grid.RowDefinitions> 22 23 <!--TitlePanel 包含应用程序的名称和页标题--> 24 <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 25 <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/> 26 <TextBlock x:Name="PageTitle" Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 27 </StackPanel> 28 29 <!--ContentPanel - 在此处放置其他内容--> 30 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 31 <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="162,213,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" /> 32 </Grid> 33 </Grid> 34 <!--演示 ApplicationBar 用法的示例代码--> 35 <!--<phone:PhoneApplicationPage.ApplicationBar> 36 <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> 37 <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="按钮 1"/> 38 <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="按钮 2"/> 39 <shell:ApplicationBar.MenuItems> 40 <shell:ApplicationBarMenuItem Text="菜单项 1"/> 41 <shell:ApplicationBarMenuItem Text="菜单项 2"/> 42 </shell:ApplicationBar.MenuItems> 43 </shell:ApplicationBar> 44 </phone:PhoneApplicationPage.ApplicationBar>--> 45 46 </phone:PhoneApplicationPage>
此处,用了行号,可能给想直接复制的同学带来麻烦,解决办法可以直接将代码放到word上,
然后工具栏处可以直接将行号取消。。当然,做编程,还是很推荐用手敲的,即使是照抄也会
有收获。
好啦,言归正传:接下来是后台CS代码:
View Code
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 15 namespace tubiao1 16 { 17 public partial class MainPage : PhoneApplicationPage 18 { 19 // Constructor 20 public MainPage() 21 { 22 InitializeComponent(); 23 } 24 25 private void button1_Click(object sender, RoutedEventArgs e) 26 { 27 ShellTile tile = ShellTile.ActiveTiles.First(); 28 StandardTileData NewTitleData = new StandardTileData 29 { 30 //前面 31 Title = "记忆", 32 BackgroundImage = new Uri("Images/blue.png", UriKind.Relative), 33 Count = 0, 34 //背面 35 BackTitle = "背面", 36 BackBackgroundImage = new Uri("Images/green.png", UriKind.Relative), 37 BackContent = "记忆点滴" 38 }; 39 40 tile.Update(NewTitleData); 41 } 42 } 43 }
运行一下试试,此时,通过用户应用程序列表中长按应用程序来把应用程序固定到“开始”屏幕。
那么,如何删除呢?在“开始”屏幕上找到你要移除的图块,长按,图块左上角会出现一个小图标,
我们点击这小图标即可移除该磁贴。当然了,如果你想把移动到其它位置,在此时,你只需把图
标拖到对应的位置,然后在桌面上随便点一下即可完成移动操作。
是不是遇到麻烦了,图片没显示……………………………………………………………………………………(此处难倒好多人)。
解决办法,在添加的图片处右击图片点属性,在出现的窗口中将生成操作(由Resource改为内容)。
再试一次,是不是就行了。。。。。好啦,此节课就到这里,最后送给大家一个笑话:
熊猫深爱着小鹿,表达爱意时却遭到拒绝。 熊猫大吼~为什麼?这一切都是为什麼?
小鹿胆怯地说:我妈说了,戴墨镜的都是不良少年