Windows 8 C#: Windows.Ui.Xaml.Media.ImageSource change Image

元气小坏坏 提交于 2020-01-05 05:26:31

问题


WARNING There are two different ImageSources in Windows API

  • System.Windows.Media.ImageSource = The one of Windows Forms
  • Windows.Ui.Xaml.Media.ImageSource = The one of Windows Store Apps

I'm a beginner in C# and Windows 8 Metro Style App programming stuff.

But if you want to edit the image of a Image, the "old" method with BitmapImage won't work:

XAML:

<Image Source="http://image.source.de" x:Name="Image1" />

Code-Behind C#:

Image1.Source = new BitmapImage...

won't work. The compiler will say something like

"System.Windows.Media.Imaging.BitmapImage" can't be converted to "Windows.Ui.Xaml.Media.ImageSource"

(Yes, BitmapImage can usually be converted to System.Windows.Media.ImageSource)

(System.Windows.Media.Imaging isn't anymore in the default import list of Visual Studio for Windows (StoreApps), you need to bind PresentationCore.dll first.)

So - is there any solution to edit Image1.Source than using Bindings?


回答1:


This should work.

Image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new System.Uri("http://image.source.de"))


来源:https://stackoverflow.com/questions/22560144/windows-8-c-windows-ui-xaml-media-imagesource-change-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!