Silverlight For WinEmbedded 的页面切换实现

Silverlight For WinEmbedded 的页面切换实现,第1张

概述本文章的基础是:新建 WinCE7.0 下的 Silverlight 工程( http://www.voidcn.com/article/p-weuvoiop-bag.html) 前一段时间在研究 Silverlight 应用在 Windows Embdeed 下的使用。还在 Silverlight 论坛发帖子求助页面切换的问题,最后没有答案(帖子见: http://bbs.csdn.net/to 本文章的基础是:新建 WinCE7.0 下的 Silverlight 工程( http://www.voidcn.com/article/p-weuvoiop-bag.html)

前一段时间在研究 Silverlight 应用在 windows Embdeed 下的使用。还在 Silverlight 论坛发帖子求助页面切换的问题,最后没有答案(帖子见: http://bbs.csdn.net/topics/390832361)。
在 windows Embedded 下只能使用 C++ 配合 Silverlight 使用,但在 PC 上一般使用的是 C#,包括 windows Phone 的开发,前期也只支持 C#。从 windows Phone 8.1 开发,好像是支持 C++了。但这方面的资料太少!
建立一个基于 C++ 的 Silverlight 工程,还是比较麻烦的。特别是对 XAML 的处理,一般建议是在 Microsoft Expression Blend 3 中完成。
在安装 Silverlight for windows Embedded 后,在新建项目中会多一个模板:Silverlight for WinoDWs Embedded Application,可以使用这个模板来创建基于 Silverlight 的应用。按向导一步步执行,最关键的一步是选择使用 Blend 创建的包含 XAML 的工程和默认的启动页面。
创建成功的 Demo,偶已经上传到 CSDN 下载频道。下载地址如下: http://download.csdn.net/detail/91program/7745251
页面切换的方法是以 MainPage 中的 GrID 为基础,在 GrID 中载入其它的 xaml 资源。即先显示 MainPage页面(一般为有一个或多个 GrID 的空页面),然后根据加载条件,载入不同的页面。


关键的代码和 XAML 如下:
1. MainPage.cpp 
HRESulT MainPage::InitializeComponent(){  HRESulT hr = E_FAIL;  m_clickDelegate = NulL;  Findname(L"LayoutRoot",&m_pLayoutRoot);  Findname(L"Gird_Layer_Source",&m_pGird_Layer_Source);  if (m_pLayoutRoot && m_pGird_Layer_Source)  {    hr = S_OK;  }  return hr;}



2.MainPage.xaml
<UserControl  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  xmlns:local="clr-namespace:WinEmbeddedHelloWorld"  x:Class="WinEmbeddedHelloWorld.MainPage"  WIDth="800" Height="480">  <GrID x:name="LayoutRoot" Background="Black">    <GrID x:name="Gird_Layer_Source" margin="0,0">    </GrID>      </GrID></UserControl>


3. App.cpp 
1) 页面注册
HRESulT App::RegisterUserControls(){    HRESulT hr = S_OK;    static PFN_XRCUC_REGISTER pfn[] =     {        &MainPage::Register,&SecondPage::Register,};    for (int i=0; i<_countof(pfn) && SUCCEEDED(hr); i++)    {        hr = pfn[i]();        if (Failed(hr))        {            RETAILMSG(1,(L"RegisterUserControls Failed."));        }    }        return hr;} // RegisterUserControls


4. App.cpp 页面切换功能的实现
1) 全局变量
IXRGrIDPtr gpMainLayer = NulL;


2) 赋值
HRESulT App::CreateHost(XRWindowCreateParams* pCreateParams){  XRPtr<IXRCustomUserControl>  pControl;  HRESulT hr = E_FAIL;  hr = m_pApplication->CreateObject(__uuIDof(MainPage),&pControl);  if (SUCCEEDED(hr))  {    hr = m_pApplication->CreateHostfromElementTree(pControl,pCreateParams,&m_pVisualHost);  }  IXRApplication *pApp = NulL;  App::GetApplication(&pApp);  IXRCustomUserControl *p1 = (IXRCustomUserControl *)pControl;  MainPage *pMainPage = dynamic_cast<MainPage *>(p1);  gpMainLayer = pMainPage->m_pGird_Layer_Source;			// 记录显示的基础 GrID  pMainPage = NulL;  return hr;}

3) 测试页面切换
HRESulT App::OnStartup(){  HRESulT hr = S_OK;  IXRFrameworkElementPtr pRoot;  hr = m_pVisualHost->GetRootElement(&pRoot);  if (SUCCEEDED(hr))  {    // Todo: Add one time initialization code here.  }  // Leo 测试页面显示,即页面切换(从 MainPage 切换到 SecondPage)  if(NulL != gpMainLayer)  {    XRPtr<SecondPage> pSwitchPage = NulL;    IXRUIElementCollection *pChildList = NulL;    gpMainLayer->GetChildren(&pChildList);    if(NulL == pChildList)    {      return NulL;    }    {      HRESulT hr = m_pApplication->CreateObject(__uuIDof(SecondPage),&pSwitchPage);      if(SUCCEEDED(hr) && NulL != pSwitchPage)      {        // pSwitchPage->OnLoad();        pChildList->Add(pSwitchPage,NulL);      }    }  }  return hr;} // OnStartup


5 SecondPage.xaml
<UserControl  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  mc:Ignorable="d"  x:Class="WinEmbeddedHelloWorld.SecondPage"  d:DesignWIDth="640" d:DesignHeight="480" WIDth="800">  <GrID x:name="LayoutRoot" Background="Green">    <button Height="38" HorizontalAlignment="left" margin="65,54,0" VerticalAlignment="top" WIDth="177" Content="Second Page"/>    <button Height="38" HorizontalAlignment="left" margin="65,117,0" VerticalAlignment="top" WIDth="177" Content="Origin Prj"/>  </GrID>  </UserControl>
总结

以上是内存溢出为你收集整理的Silverlight For WinEmbedded 的页面切换实现全部内容,希望文章能够帮你解决Silverlight For WinEmbedded 的页面切换实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1013389.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存