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

Windows Phone 7開發(fā)小技巧

移動開發(fā)
本文介紹了六種Windows Phone 7開發(fā)小技巧,其中包括使用Popup來實現(xiàn)自定義的彈出效果、捕獲物理按鍵返回鍵,打開頁面,離開頁面等等。

1.使用Popup來實現(xiàn)自定義的彈出效果。Popup控件彈出的塊會一直在屏幕的最前方,所以使用Popup可以實現(xiàn)各種各樣的彈出框,并且給了你極大的自定義的空間,很多第三方的彈出框控件的原理其實就是使用了Popup來包裝上各種效果來實現(xiàn)的。

Popup使用的方法:

  1. private Popup popup;  
  2. popup = new Popup();  
  3. popup.Child = new 控件類();  
  4. //打開  
  5. popup.IsOpen = true;  
  6. //關閉  
  7. popup.IsOpen = false 

或者(xaml代碼)

  1. <Popup x:Name="popup"> 
  2.     <Border> 
  3.        <StackPanel> 
  4.             ……  
  5.         </StackPanel> 
  6.     </Border> 
  7. </Popup> 

或者(cs代碼)

  1. //打開  
  2. popup.IsOpen = true;  
  3. //關閉  
  4. popup.IsOpen = false 

2.在TextBlock控件中使用<LineBreak></LineBreak>進行換行。

  1. <TextBlock TextWrapping="Wrap"> 
  2.           測試            
  3.    <LineBreak></LineBreak> 
  4.    <LineBreak></LineBreak> 
  5.           測試  
  6.    <LineBreak></LineBreak> 
  7.    <LineBreak></LineBreak> 
  8.           測試  
  9. </TextBlock> 

3.捕獲物理按鍵返回鍵,打開頁面,離開頁面。Wndows Pone有3個物理按鍵,返回鍵,開始鍵,搜索鍵,后面兩個無法在程序中捕獲到。

  1. //點擊返回按鈕  
  2. protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)    
  3. {  
  4.     //你的代碼  
  5.     e.Cancel = false;             
  6.     base.OnBackKeyPress(e);    
  7. }   
  8. //從其他頁面進入該頁面  
  9. protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)  
  10. {  
  11.      //你的代碼  
  12.      base.OnNavigatedTo(e);  
  13. }  
  14. //離開當前的頁面  
  15. protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)  
  16. {  
  17.    //你的代碼  
  18.    base.OnNavigatedFrom(e);  

4.獲取父控件里面的子控件的方法。之前在判斷ListBox控件什么時候滾到底的時候使用過該方法,這個方法很常用。

  1. //獲取***個子類型   
  2.         public static T FindChildOfType<T>(DependencyObject root) where T : class  
  3.         {  
  4.             var queue = new Queue<DependencyObject>();  
  5.             queue.Enqueue(root);  
  6.             while (queue.Count > 0)  
  7.             {  
  8.                 DependencyObject current = queue.Dequeue();  
  9.                 for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 0 <= i; i--)  
  10.                 {  
  11.                     var child = VisualTreeHelper.GetChild(current, i);  
  12.                     var typedChild = child as T;  
  13.                     if (typedChild != null)  
  14.                     {  
  15.                         return typedChild;  
  16.                     }  
  17.                     queue.Enqueue(child);  
  18.                 }  
  19.             }  
  20.             return null;  
  21.         }  
  22.  
  23.         //獲取所有的子類型  
  24.         public static List<T> FindAllChildOfType<T>(DependencyObject root) where T : class  
  25.         {  
  26.             var queue = new Queue<DependencyObject>();  
  27.             queue.Enqueue(root);  
  28.             List<T> allChild = new List<T>();  
  29.             while (queue.Count > 0)  
  30.             {  
  31.                 DependencyObject current = queue.Dequeue();  
  32.                 for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 0 <= i; i--)  
  33.                 {  
  34.                     var child = VisualTreeHelper.GetChild(current, i);  
  35.                     var typedChild = child as T;  
  36.                     if (typedChild != null)  
  37.                     {  
  38.                         allChild.Add(typedChild);  
  39.                     }  
  40.                     queue.Enqueue(child);  
  41.                 }  
  42.             }  
  43.             return allChild;  
  44.         } 


5.使用<ControlTemplate>……</ControlTemplate>來擴展控件的各種自定義化的效果,當你需要在控件上實現(xiàn)一些動畫的效果,或者在控件上再嵌入其他的一些控件都可以通過設計一個ControlTemplate來實現(xiàn)。

如實現(xiàn)一個按鈕的單擊效果:

  1. <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="103,197,0,0" Name="button1" VerticalAlignment="Top" Width="160"> 
  2.                 <Button.Template> 
  3.                     <ControlTemplate> 
  4.                         <Grid Background="Transparent"> 
  5.                             <VisualStateManager.VisualStateGroups> 
  6.                                 <VisualStateGroup x:Name="CommonStates"> 
  7.                                     <VisualState x:Name="Pressed"> 
  8.                                         <Storyboard> 
  9.                                             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background"> 
  10.                                                 <DiscreteObjectKeyFrame KeyTime="0" Value="YellowGreen"/> 
  11.                                             </ObjectAnimationUsingKeyFrames> 
  12.                                             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="BorderBrush"> 
  13.                                                 <DiscreteObjectKeyFrame KeyTime="0" Value="YellowGreen"/> 
  14.                                             </ObjectAnimationUsingKeyFrames> 
  15.                                         </Storyboard> 
  16.                                     </VisualState> 
  17.                                 </VisualStateGroup> 
  18.                             </VisualStateManager.VisualStateGroups> 
  19.                             <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"  Background="{TemplateBinding Background}" Margin="{StaticResource PhoneTouchTargetOverhang}"> 
  20.                                 <ContentControl x:Name="ContentContainer" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Padding="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
  21.                             </Border> 
  22.                         </Grid> 
  23.                     </ControlTemplate> 
  24.                 </Button.Template> 
  25.             </Button> 

6.顯示和隱藏手機的頂部托盤,就是頂部那個信號和電池信息那塊東西。

  1. //顯示  
  2. SystemTray.IsVisible = true;  
  3. //隱藏  
  4. SystemTray.IsVisible = false

遇到一個問題:ApplicationBar的高度無法自定義,當ApplicationBarMenuItem為偶數(shù)的時候,下面還多了一大截的空間很影響美觀(為奇數(shù)的時候就不會多出這一大截的空間,不知道微軟為何要這樣設計),大家有沒有相關的解決方法呢?

 

 

原文鏈接http://www.cnblogs.com/linzheng/archive/2011/10/27/2226990.html

責任編輯:王曉東 來源: 博客園
相關推薦

2013-04-17 10:45:26

Windows PhoWindows Pho

2012-06-25 16:14:26

Windows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2011-06-07 11:35:38

Windows Pho

2010-12-14 18:48:49

微軟

2010-04-08 17:40:23

Windows Pho

2010-03-09 10:51:15

Windows Pho

2010-08-13 08:21:11

Windows Pho

2013-07-31 13:36:07

Windows PhoVS調試技巧Windows Pho

2009-11-06 18:58:21

Windows 7雙系統(tǒng)卸載

2010-07-21 14:42:15

Windows Pho

2011-03-30 11:21:41

Windows Pho開發(fā)大賽

2013-04-17 10:24:29

Windows Pho

2012-05-08 15:03:53

Windows7庫功能

2010-08-10 13:21:41

Windows PhoWindows Pho

2012-06-13 13:01:57

Windows Pho

2012-08-02 10:16:39

Windows Pho

2010-12-21 10:02:48

SilverlightWindows Pho

2010-11-03 15:10:04

SilverlightSilverlightWindows Pho

2010-12-16 10:06:31

Windows Pho
點贊
收藏

51CTO技術棧公眾號