2KB项目,专业的源码交易网站 帮助 收藏 每日签到

编程创建 Windows Phone 的全景应用 (Panorama)

  • 时间:2019-01-23 18:44 编辑:2KB 来源:2KB.COM 阅读:370
  • 扫一扫,手机访问
  • 分享
摘要:
Windows Phone 英文原文:How To: Programmatically Create a Panorama Control in Windows Phone

在这个教程中我们将学习如何创建一个包含动态全景控件的 Windows Phone 7 应用程序。关于什么是全景控件请看本文最后的运行截图。

首先打开 Visual Studip 2010 并创建一个新的 Sliverlight for Windows Phone 7 的项目:

开始编码之前,我们通过添加引用选项来添加 Microsoft.Phone.Controls 的引用,并在 XAML 代码中包含命名空间,并删除 xaml 代码中的默认内容:

现在让我们开始编码。全景空间包含不同的标题和条目:

private List<string> CreatePanoramaItems(string item)
{
    List<String> Panoramaitems = null;
    switch (item)
    {
	case "Page1":
	    Panoramaitems = new List<string> { "Page1Item1", "Page1Item2", "Page1Item3"};
	    break;
	case "Page2":
	    Panoramaitems = new List<string> { "Page2Item1", "Page2Item2", "Page2Item3" };
	    break;
	case "Page3":
	    Panoramaitems = new List<string> { "Page3Item1", "Page3Item2", "Page3Item3" };
	    break;
    }
    return Panoramaitems;
}

private List<string> CreatePanoramaHeaders()
{
    return new List<string> { "Page1", "Page2", "Page3" };
}

接下来是添加装载事件,当页面加载时我们要装载动态的全景控件,并自定义标题和列表项:

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
   //Initializing the Panorama Control and Assigning base values
   Panorama panoramactrl = new Panorama();
   panoramactrl.Title = "F5Debug How To";
   panoramactrl.SelectionChanged += panoramaCtrl_SelectionChanged;
  
   //Initializing the Panorama Control Items
   PanoramaItem panoramaCtrlItem = new PanoramaItem();
   panoramaCtrlItem.Header = "Dynamic Panorama";

   //Initializing Textblock to display some text
   TextBlock textBlock = new TextBlock();
   textBlock.TextWrapping = TextWrapping.Wrap;
   textBlock.Text = "F5debug.Net – Building and Debugging the Technology";
   textBlock.FontSize = 20;
   panoramaCtrlItem.Content = textBlock;

   panoramactrl.Items.Add(panoramaCtrlItem);

   foreach (string Eachitems in CreatePanoramaHeaders())
   {
       panoramaCtrlItem = new PanoramaItem();
       panoramaCtrlItem.Header = Eachitems;
       panoramactrl.Items.Add(panoramaCtrlItem);
   }

   this.LayoutRoot.Children.Add(panoramactrl);
}

private void panoramaCtrl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   Panorama panoramactrl = (Panorama)sender;
   PanoramaItem panoramaItem = (PanoramaItem)(panoramactrl.SelectedItem);

   if (panoramaItem.Content == null)
   {
       ListBox listBox = new ListBox();
       listBox.ItemsSource = CreatePanoramaItems(panoramaItem.Header.ToString());
       panoramaItem.Content = listBox;
   }
} 

完整代码列表:

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 F5debugHowto43
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        private List<string> CreatePanoramaItems(string item)
        {
            List<String> Panoramaitems = null;
            switch (item)
            {
                case "Page1":
                    Panoramaitems = new List<string> { "Page1Item1", "Page1Item2", "Page1Item3"};
                    break;
                case "Page2":
                    Panoramaitems = new List<string> { "Page2Item1", "Page2Item2", "Page2Item3" };
                    break;
                case "Page3":
                    Panoramaitems = new List<string> { "Page3Item1", "Page3Item2", "Page3Item3" };
                    break;
            }
            return Panoramaitems;
        }

        private List<string> CreatePanoramaHeaders()
        {
            return new List<string> { "Page1", "Page2", "Page3" };
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            //Initializing the Panorama Control and Assigning base values
            Panorama panoramactrl = new Panorama();
            panoramactrl.Title = "F5Debug How To";
            panoramactrl.SelectionChanged += panoramaCtrl_SelectionChanged;
           
            //Initializing the Panorama Control Items
            PanoramaItem panoramaCtrlItem = new PanoramaItem();
            panoramaCtrlItem.Header = "Dynamic Panorama";

            //Initializing Textblock to display some text
            TextBlock textBlock = new TextBlock();
            textBlock.TextWrapping = TextWrapping.Wrap;
            textBlock.Text = "F5debug.Net – Building and Debugging the Technology";
            textBlock.FontSize = 20;
            panoramaCtrlItem.Content = textBlock;

            panoramactrl.Items.Add(panoramaCtrlItem);

            foreach (string Eachitems in CreatePanoramaHeaders())
            {
                panoramaCtrlItem = new PanoramaItem();
                panoramaCtrlItem.Header = Eachitems;
                panoramactrl.Items.Add(panoramaCtrlItem);
            }

            this.LayoutRoot.Children.Add(panoramactrl);
        }

        private void panoramaCtrl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Panorama panoramactrl = (Panorama)sender;
            PanoramaItem panoramaItem = (PanoramaItem)(panoramactrl.SelectedItem);

            if (panoramaItem.Content == null)
            {
                ListBox listBox = new ListBox();
                listBox.ItemsSource = CreatePanoramaItems(panoramaItem.Header.ToString());
                panoramaItem.Content = listBox;
            }
        }

    }
}

现在我们已经完成了所有的编码工作,按 F5 直接运行看看效果,如果编译成功的话会打开 Windows Phone 模拟器,然后你可以看到如下运行结果:

Output Screen:

在这个教程中,我们学习如何编程加载动态的全景控件以及自定义标题和列表项。

Happy Programming!!!

本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接。 2KB翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。


2KB项目(www.2kb.com,源码交易平台),提供担保交易、源码交易、虚拟商品、在家创业、在线创业、任务交易、网站设计、软件设计、网络兼职、站长交易、域名交易、链接买卖、网站交易、广告买卖、站长培训、建站美工等服务

  • 全部评论(0)
资讯详情页最新发布上方横幅
最新发布的资讯信息
【计算机/互联网|】Nginx出现502错误(2020-01-20 21:02)
【计算机/互联网|】网站运营全智能软手V0.1版发布(2020-01-20 12:16)
【计算机/互联网|】淘宝这是怎么了?(2020-01-19 19:15)
【行业动态|】谷歌关闭小米智能摄像头,因为窃听器显示了陌生人家中的照片(2020-01-15 09:42)
【行业动态|】据报道谷歌新闻终止了数字杂志,退还主动订阅(2020-01-15 09:39)
【行业动态|】康佳将OLED电视带到美国与LG和索尼竞争(2020-01-15 09:38)
【行业动态|】2020年最佳AV接收机(2020-01-15 09:35)
【行业动态|】2020年最佳流媒体设备:Roku,Apple TV,Firebar,Chromecast等(2020-01-15 09:31)
【行业动态|】CES 2020预览:更多的流媒体服务和订阅即将到来(2020-01-08 21:41)
【行业动态|】从埃隆·马斯克到杰夫·贝佐斯,这30位人物定义了2010年代(2020-01-01 15:14)
联系我们

Q Q: 7090832

电话:400-0011-990

邮箱:7090832@qq.com

时间:9:00-23:00

联系客服
商家入住 服务咨询 投拆建议 联系客服
0577-67068160
手机版

扫一扫进手机版
返回顶部