问题
I cannot figure out how to dynamically load an image from the disk to a Xaml image control.
<Image x:Name="imgLogo" ....../>
Then in my c++ class, i cannot get any examples working that I have found. Most are in c#. One annoyance is that I keep seeing System.Windows.Media::ImageSource used, but that is not in my framework.
Can someone please show me an example. I'm coming from the iOS world and am not used to MS and their frameworks.
Thanks,
回答1:
Try this, it's in C# but should be fairly easy to convert:
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;
}
}
Taken from here (my blog).
To change the image, just change the value of bmImage
and call NotifyPropertyChanged(()=>BMImage);
(assuming you have that setup)
See here for Microsoft's example of how to use images.
See here for the Windows.UI.Xaml.Media.Imaging
namespace.
来源:https://stackoverflow.com/questions/12323864/change-image-source-programmatically