简体   繁体   English

如何在“ Windows Embedded的XAML(Compact 2013)”中切换图像

[英]How do I switch an image in “XAML for Windows Embedded (Compact 2013)”

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. 我有一个Windows CE项目,该项目将XAML用于Windows Embedded(紧凑版2013) (也称为“用于Windows Embedded的Silverlight”)用于GUI。

I defined an image in xaml and now I want to switch this image in the c++ code behind part. 我在xaml中定义了一个图像,现在我想在部分后面的c ++代码中切换此图像。

How do I do this? 我该怎么做呢?

I found this solution: 我找到了这个解决方案:

m_pBatteryStateImage is the image, defined in Xaml. m_pBatteryStateImage是在Xaml中定义的图像。

The URIs for the images can be found in the auto generated file PROJECTNAMEGenerated.rc2 可以在自动生成的文件PROJECTNAMEGenerated.rc2找到图像的URI。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在“适用于Windows Embedded的XAML(Compact 2013)”项目中获取图像的可靠源URI。 - Get robust source URIs for Images in “XAML for Windows Embedded (Compact 2013)” projects Windows Embedded Compact 2013-初始应用重点 - Windows Embedded Compact 2013 - Initial Application Focus 如何将Windows Embedded Compact 7 DLL移植到Windows CE 5.0 / 6.0? - How to Port Windows Embedded Compact 7 DLL to Windows CE 5.0 / 6.0? QueryPerformanceCounter()测试Windows Embedded Compact 7 - QueryPerformanceCounter() Test for Windows Embedded Compact 7 意外的 IConnectionPointImpl::Unadvise 调用 Windows Embedded Compact 7 - Unexpected IConnectionPointImpl::Unadvise call on Windows Embedded Compact 7 如何在VC2013 for C ++中关闭自动制表开关/大小写? - How do I turn off auto-tabbing switch/case in VC2013 for C++? 哪个文件配置Windows Embedded Compact 7.0上的缓存? - Which file configures caching on Windows Embedded Compact 7.0? 如何压缩 C 中字符串中的连续重复元素? - How do I compact contiguous repeated elements in a string in C? Windows Embedded的Silverlight:如何在xaml和后台代码之间传递imagesource依赖项属性 - Silverlight for Windows Embedded: how to communicate imagesource Dependency Property between xaml and code-behind 如何使用switch语句? - How do I use the switch statement?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM