ユニークwindows phone(2)-Control(コントロール)

74755 ワード

[インデックス・ページ] [ソースのダウンロード]
ユニークwindows phone(2)-Control(コントロール)
作者:webabcd紹介変わったwindows phone 7.5(sdk 7.1)のコントロール
  • Panorama-パノラマコントロール
  • Pivot-ピボットコントロール
  • Map-bing地図コントロール
  • WebBrowser-組み込みブラウザコントロール
  • Other-その他の使用可能なコントロール
  • 例1、PanoramaのDemoPanorama.xaml
    <phone:PhoneApplicationPage 
        x:Class="Demo.Controls.Panorama"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait"  Orientation="Portrait"
        shell:SystemTray.IsVisible="False"
        
        xmlns:sys="clr-namespace:System;assembly=mscorlib">
    
        <Grid x:Name="LayoutRoot">
            <!--
                Panorama -      
                    Title - Panorama    
                    Background - Panorama    
            -->
            <controls:Panorama x:Name="panorama" Title="Title">
    
                <controls:Panorama.Background>
                    <ImageBrush ImageSource="/Controls/Assets/diandian.jpg"/>
                </controls:Panorama.Background>
    
                <!--
                    PanoramaItem - Panorama   
                        Header - PanoramaItem     
                        Orientation - PanoramaItem          (Vertical   Horizontal),     Vertical
                -->
                <controls:PanoramaItem Header="Item 01">
                    <Grid>
                        <StackPanel>
                            <TextBlock Text="    ,          " Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="Wrap"/>
                            <TextBlock Text="    ,           " Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="NoWrap"/>
                        </StackPanel>
                    </Grid>
                </controls:PanoramaItem>
    
                <controls:PanoramaItem Header="Item 02" Orientation="Horizontal">
                    <Grid>
                        <Border BorderBrush="{StaticResource PhoneForegroundBrush}"
                                BorderThickness="{StaticResource PhoneBorderThickness}"
                                Background="#80808080">
                            <TextBlock Text="      ,          "
                                       Style="{StaticResource PhoneTextExtraLargeStyle}"
                                       HorizontalAlignment="Center" VerticalAlignment="Center" >
                            </TextBlock>
    
                        </Border>
                    </Grid>
                </controls:PanoramaItem>
    
                <!--
                         PanoramaItem             ,    Orientation     Horizontal
                       PanoramaItem           ,    ListBox      
                -->
                <controls:PanoramaItem Header="Item 03" Orientation="Horizontal">
                    <StackPanel Orientation="Horizontal">
                        <ListBox FontSize="{StaticResource PhoneFontSizeLarge}" Width="480">
                            <sys:String>a</sys:String>
                            <sys:String>b</sys:String>
                            <sys:String>c</sys:String>
                            <sys:String>d</sys:String>
                            <sys:String>e</sys:String>
                            <sys:String>f</sys:String>
                            <sys:String>g</sys:String>
                            <sys:String>h</sys:String>
                            <sys:String>i</sys:String>
                            <sys:String>j</sys:String>
                            <sys:String>k</sys:String>
                            <sys:String>l</sys:String>
                            <sys:String>m</sys:String>
                            <sys:String>n</sys:String>
                            <sys:String>o</sys:String>
                            <sys:String>p</sys:String>
                            <sys:String>q</sys:String>
                            <sys:String>r</sys:String>
                        </ListBox>
                        <TextBlock Text="webabcd" />
                    </StackPanel>
                </controls:PanoramaItem>
    
            </controls:Panorama>
        </Grid>
    
    </phone:PhoneApplicationPage>

    Panorama.xaml.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    
    namespace Demo.Controls
    {
        public partial class Panorama : PhoneApplicationPage
        {
            public Panorama()
            {
                InitializeComponent();
    
                this.Loaded += new RoutedEventHandler(Panorama_Loaded);
            }
    
            void Panorama_Loaded(object sender, RoutedEventArgs e)
            {
                /*
                 * Panorama -      
                 *     DefaultItem -    Panorama         
                 *     SelectionChanged -               (     Panorama,   item       )
                 *     SelectedIndex -       
                 *     SelectedItem -    
                 */
    
                panorama.DefaultItem = panorama.Items[1];
            }
        }
    }

    2、PivotのDemoPivot.xaml
    <phone:PhoneApplicationPage 
        x:Class="Demo.Controls.Pivot"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait"  Orientation="Portrait"
        shell:SystemTray.IsVisible="True"
        
        xmlns:sys="clr-namespace:System;assembly=mscorlib">
    
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <!--
                Pivot -     
                    Title - Pivot    
                    Background - Pivot    
            -->
            <controls:Pivot Title="Title">
    
                <!--
                    PivotItem - Pivot   
                        Header - PivotItem     
                -->
                <controls:PivotItem Header="Item 01">
                    <Grid>
                        <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}">
                            <Run>webabcd</Run>
                            <LineBreak/>
                            <Run>windows phone</Run>
                        </TextBlock>
                    </Grid>
                </controls:PivotItem>
    
                <controls:PivotItem Header="Item 02">
                    <Border BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="{StaticResource PhoneBorderThickness}">
                        <Grid>
                            <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"
                                       Text="wp7" />
                        </Grid>
                    </Border>
                </controls:PivotItem>
    
                <controls:PivotItem Header="Item 03">
                    <Grid>
                        <ListBox FontSize="{StaticResource PhoneFontSizeLarge}">
                            <sys:String>a</sys:String>
                            <sys:String>b</sys:String>
                            <sys:String>c</sys:String>
                            <sys:String>d</sys:String>
                            <sys:String>e</sys:String>
                            <sys:String>f</sys:String>
                            <sys:String>g</sys:String>
                            <sys:String>h</sys:String>
                            <sys:String>i</sys:String>
                            <sys:String>j</sys:String>
                            <sys:String>k</sys:String>
                            <sys:String>l</sys:String>
                            <sys:String>m</sys:String>
                            <sys:String>n</sys:String>
                            <sys:String>o</sys:String>
                            <sys:String>p</sys:String>
                            <sys:String>q</sys:String>
                            <sys:String>r</sys:String>
                        </ListBox>
                    </Grid>
                </controls:PivotItem>
    
            </controls:Pivot>
        </Grid>
    
    </phone:PhoneApplicationPage>

    3、Bing MapのDemoMap.xaml
    <phone:PhoneApplicationPage 
        x:Class="Demo.Controls.Map"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True"
        
        xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps">
    
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <StackPanel Orientation="Vertical">
                
                <!--
                    Map - bing     
                -->
                <my:Map x:Name="map" />
    
                <Button x:Name="btnZoomIn" Content="  " Click="btnZoomIn_Click" />
                <Button x:Name="btnZoomOut" Content="  " Click="btnZoomOut_Click" />
                <Button x:Name="btnRoad" Content="   " Click="btnRoad_Click" />
                <Button x:Name="btnAerial" Content="   " Click="btnAerial_Click" />
    
            </StackPanel>
        </Grid>
    </phone:PhoneApplicationPage>

    Map.xaml.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Controls.Maps;
    
    namespace Demo.Controls
    {
        public partial class Map : PhoneApplicationPage
        {
            public Map()
            {
                InitializeComponent();
    
                this.Loaded += new RoutedEventHandler(Map_Loaded);
            }
    
            void Map_Loaded(object sender, RoutedEventArgs e)
            {
                /*
                 * Map - bing     
                 *     Center -         
                 *     Mode -     。RoadMode:    ,AerialMode:   
                 *     ZoomLevel -        
                 */
    
                map.Center = new System.Device.Location.GeoCoordinate(39.9, 116.3);
                map.ZoomLevel = 10;
            }
    
            private void btnRoad_Click(object sender, RoutedEventArgs e)
            {
                map.Mode = new RoadMode();
            }
    
            private void btnAerial_Click(object sender, RoutedEventArgs e)
            {
                map.Mode = new AerialMode();
            }
    
            private void btnZoomIn_Click(object sender, RoutedEventArgs e)
            {
                map.ZoomLevel++;
            }
    
            private void btnZoomOut_Click(object sender, RoutedEventArgs e)
            {
                map.ZoomLevel--;
            }
        }
    }

    4、WebBrowserのDemoWebBrowser.xaml
    <phone:PhoneApplicationPage 
        x:Class="Demo.Controls.WebBrowser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True">
    
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <StackPanel Orientation="Vertical">
                
                <!--
                    WebBrowser -        
                        Source -             
                -->
                <phone:WebBrowser x:Name="webBrowser" Width="480" Height="480" Source="http://webabcd.cnblogs.com/" IsScriptEnabled="True" />
                
                <Button x:Name="btnNavigateRemoteUrl" Content="          " Click="btnNavigateRemoteUrl_Click" />
                <Button x:Name="btnNavigateLocalUrl" Content="          " Click="btnNavigateLocalUrl_Click" />
                <Button x:Name="btnScript" Content="    " Click="btnScript_Click" />
                
            </StackPanel>
        </Grid>
    
    </phone:PhoneApplicationPage>

    WebBrowser.xaml.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using System.Windows.Resources;
    using System.IO;
    
    namespace Demo.Controls
    {
        public partial class WebBrowser : PhoneApplicationPage
        {
            public WebBrowser()
            {
                InitializeComponent();
    
                webBrowser.ScriptNotify += new EventHandler<NotifyEventArgs>(webBrowser_ScriptNotify);
            }
    
            private void btnNavigateRemoteUrl_Click(object sender, RoutedEventArgs e)
            {
                /*
                 * WebBrowser -        
                 *     Source -             
                 *     Navigate() -         ,   (    WebBrowser    Loaded          ,     )
                 *     LoadCompleted - WebBrowser                
                 *     NavigateToString() -         
                 *     SaveToString() -      WebBrowser      HTML   ,         
                 *     IsGeolocationEnabled -               
                 *     IsScriptEnabled -           
                 *     InvokeScript() -      WebBrowser      HTML      JavaScript   
                 *     ScriptNotify -   WebBrowser    JavaScript   “window.external.notify(string);”          windows phone app        
                 *         NotifyEventArgs - ScriptNotify        
                 *         NotifyEventArgs.Value - JavaScript     windows phone app     ,  “window.external.notify(string);”      
                 */
    
                webBrowser.Source = new Uri("http://msdn.microsoft.com/");
                // webBrowser.Navigate(new Uri("http://msdn.microsoft.com/"));
            }
    
            private void btnNavigateLocalUrl_Click(object sender, RoutedEventArgs e)
            {
                //    WebBrowser                   ,     WebBrowser                  (Isolated Storage)
                // webBrowser.Navigate(new Uri("Controls/readme.html", UriKind.Relative));
    
                StreamResourceInfo sr = Application.GetResourceStream(new Uri("Controls/readme.html", UriKind.Relative));
                using (BinaryReader br = new BinaryReader(sr.Stream))
                {
                    byte[] data = br.ReadBytes((int)sr.Stream.Length);
                    webBrowser.NavigateToString(System.Text.Encoding.UTF8.GetString(data, 0, data.Length));
                }
            }
    
            private void btnScript_Click(object sender, RoutedEventArgs e)
            {
                webBrowser.Navigate(new Uri("http://localhost:15482/ForWebBrowser.html"));
            }
    
            void webBrowser_ScriptNotify(object sender, NotifyEventArgs e)
            {
                //    JavaScript      
                MessageBox.Show(e.Value);
    
                //    WebBrowser    JavaScript         
                MessageBox.Show((string)webBrowser.InvokeScript("hello", "webabcd"));
            }
        }
    }

    ForWebBrowser.html
    <script type="text/javascript">
    
        //        :windows phone app    WebBrowser    JavaScript   
        function hello(name) {
            return "hello: " + name;
        }
    
        //        :JavaScript      windows phone app    WebBrowser
        try {
            window.external.notify('   ');
        } catch (err) { } 
        
    </script>

    5、他のコントロールのDemoOther.xaml
    <phone:PhoneApplicationPage 
        x:Class="Demo.Controls.Other"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True">
    
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <TextBlock TextWrapping="Wrap">
                <Run>        :(      《     Silverlight     》)</Run>
                <LineBreak />
                <Run>Border</Run>
                <LineBreak />
                <Run>Buton</Run>
                <LineBreak />
                <Run>Canvas</Run>
                <LineBreak />
                <Run>CheckBox</Run>
                <LineBreak />
                <Run>Grid</Run>
                <LineBreak />
                <Run>HyperlinkButon</Run>
                <LineBreak />
                <Run>Image</Run>
                <LineBreak />
                <Run>InkPresenter</Run>
                <LineBreak />
                <Run>ListBox</Run>
                <LineBreak />
                <Run>MediaElement</Run>
                <LineBreak />
                <Run>PasswordBox</Run>
                <LineBreak />
                <Run>MultiScaleImage</Run>
                <LineBreak />
                <Run>PasswordBox</Run>
                <LineBreak />
                <Run>ProgressBar</Run>
                <LineBreak />
                <Run>RadioButton</Run>
                <LineBreak />
                <Run>RichTextBox</Run>
                <LineBreak />
                <Run>ScrollViewer</Run>
                <LineBreak />
                <Run>Slider</Run>
                <LineBreak />
                <Run>StackPanel</Run>
                <LineBreak />
                <Run>TextBlock</Run>
                <LineBreak />
                <Run>TextBox</Run>
                <LineBreak />
            </TextBlock>
        </Grid>
    
    </phone:PhoneApplicationPage>

    OK [ソースのダウンロード]