我不知道如何将图像从磁盘动态加载到 Xaml 图像控件。
<Image x:Name="imgLogo" ....../>
然后在我的 C++ 类(class)中,我找不到任何我找到的示例。大多数都在 c# 中。一个烦恼是我一直看到使用了 System.Windows.Media::ImageSource,但这不在我的框架中。
谁能给我举个例子。我来自 iOS 世界,不习惯 MS 及其框架。
谢谢,
最佳答案
试试这个,它是用 C# 编写的,但应该很容易转换:
using Windows.UI.Xaml.Media.Imaging;
<Image Margin="5" Source="{Binding BMImage}" Height="100"/>
bmImage = new BitmapImage();
bmImage.UriSource = new Uri(new Uri(
*your file path*,
*your image name*);
BitmapImage bmImage;
public BitmapImage BMImage
{
get
{
return bmImage;
}
}
取自here (我的博客)。
要更改图像,只需更改 bmImage
的值并调用 NotifyPropertyChanged(()=>BMImage);
(假设您有该设置)
参见 here Microsoft 的图像使用示例。
参见 here对于 Windows.UI.Xaml.Media.Imaging
命名空间。
关于c++ - 以编程方式更改图像源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12323864/