以编程方式更改图像源

change image source programmatically

本文关键字:图像 方式更 编程      更新时间:2023-10-16

我不知道如何将映像从磁盘动态加载到Xaml映像控件。

<Image x:Name="imgLogo" ....../>

然后在我的c++类中,我找不到任何可以使用的例子。大多数都在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;
    }
}

取自这里(我的博客)。

要更改图像,只需更改bmImage的值并调用NotifyPropertyChanged(()=>BMImage);(假设您有该设置)

有关如何使用图像的Microsoft示例,请参见此处。

请参阅此处以获取Windows.UI.Xaml.Media.Imaging命名空间。