【问题标题】:How do I switch an image in "XAML for Windows Embedded (Compact 2013)"如何在“XAML for Windows Embedded (Compact 2013)”中切换图像
【发布时间】:2017-08-25 07:41:24
【问题描述】:

我有一个 Windows CE 项目,它使用XAML for Windows Embedded (Compact 2013)(也称为“Silverlight for Windows Embedded”)作为 GUI。

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

我该怎么做?

【问题讨论】:

    标签: c++ xaml silverlight windows-ce windows-embedded


    【解决方案1】:

    我找到了这个解决方案:

    m_pBatteryStateImage是图像,在 Xaml 中定义。

    图片的 URI 可以在自动生成的文件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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      • 2013-05-26
      相关资源
      最近更新 更多