如何在“XAML for Windows Embedded (Compact 2013)"中切换图像? [英] How do I switch an image in "XAML for Windows Embedded (Compact 2013)"

查看:38
本文介绍了如何在“XAML for Windows Embedded (Compact 2013)"中切换图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows CE 项目,它使用 XAML for Windows Embedded (Compact2013)(也称为Silverlight for Windows Embedded")用于 GUI.

I have a project for Windows CE that uses XAML for Windows Embedded (Compact 2013) (also known as "Silverlight for Windows Embedded") for the GUI.

我在 xaml 中定义了一个图像,现在我想在后面的 c++ 代码中切换这个图像.

I defined an image in xaml and now I want to switch this image in the c++ code behind part.

我该怎么做?

推荐答案

我找到了这个解决方案:

I found this solution:

m_pBatteryStateImage是图像,在 Xaml 中定义.

m_pBatteryStateImageis the image, defined in Xaml.

图像的 URI 可以在自动生成的文件 PROJECTNAMEGenerated.rc2

The URIs for the images can be found in the auto generated file PROJECTNAMEGenerated.rc2

void MainPage::SetBatteryState(BatteryStateFlags batteryState)
{

    BSTR src = GetImageSourceUri(batteryState);
    SetImage(src);
}

void MainPage::SetImage(BSTR src)
{
    IXRApplication* application;
    App::GetApplication(&application);
    //Check which uri is currently used:
    BSTR originalSrc;
    IXRImageSource* iSource;
    m_pBatteryStateImage->GetSource(&iSource);
    IXRBitmapImagePtr bmpSrc = (IXRBitmapImagePtr)iSource;
    bmpSrc->GetUriSource(&originalSrc);
    //Set new image if source uri is different
    if (wcscmp(originalSrc,src)!=0) 
    {
        IXRBitmapImagePtr bitmapImage;
        application->CreateObject(IID_IXRBitmapImage, &bitmapImage);
        bitmapImage->SetUriSource(src);
        m_pBatteryStateImage->SetSource(bitmapImage);
    }
}

BSTR MainPage::GetImageSourceUri(BatteryStateFlags batteryState)
{
    BSTR src; 
    //see PROJECTNAMEGenerated.rc2 - the numbers will change if images are added (they are alphabetically sorted).
    //TODO make it robust against changes
    if(batteryState & BatteryChargerError)
        src = TEXT("#105"); 
    else if(batteryState &  BatteryHigh)
        src = TEXT("#106");
    else if(batteryState & BatteryLow)
        src = TEXT("#109");
    else
        //Show error if nothing else matches (Should not happen)
        src = TEXT("#105");
    return src;
}

这篇关于如何在“XAML for Windows Embedded (Compact 2013)"中切换图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆