0
我有一個針對Windows CE的項目,該項目爲GUI使用XAML for Windows Embedded (Compact 2013)(也稱爲「Windows Embedded的Silverlight」)。如何在「適用於Windows Embedded(Compact 2013)的XAML」中切換圖像
我在xaml中定義了一個圖像,現在我想在部分後面的C++代碼中切換此圖像。
我該怎麼做?
我有一個針對Windows CE的項目,該項目爲GUI使用XAML for Windows Embedded (Compact 2013)(也稱爲「Windows Embedded的Silverlight」)。如何在「適用於Windows Embedded(Compact 2013)的XAML」中切換圖像
我在xaml中定義了一個圖像,現在我想在部分後面的C++代碼中切換此圖像。
我該怎麼做?
我發現此解決方案:
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;
}