繁体   English   中英

Windows 8 C#:Windows.Ui.Xaml.Media.ImageSource更改图像

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

警告 Windows API中有两个不同的ImageSource

  • System.Windows.Media.ImageSource = Windows窗体之一
  • Windows.Ui.Xaml.Media.ImageSource = Windows应用商店之一

我是C#和Windows 8 Metro Style App编程知识的初学者。

但是,如果您要编辑Image ,则BitmapImage的“旧”方法将不起作用:

XAML:

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

代码隐藏的C#:

Image1.Source = new BitmapImage...

将无法正常工作。 编译器会说类似

无法将“ System.Windows.Media.Imaging.BitmapImage”转换为“ Windows.Ui.Xaml.Media.ImageSource”

(是的, BitmapImage通常可以转换为System.Windows.Media.ImageSource

(System.Windows.Media.Imaging不再位于Visual Studio for Windows(StoreApps)的默认导入列表中,您需要首先绑定PresentationCore.dll。)

那么-除了使用Binding之外,还有其他解决方案来编辑​​Image1.Source吗?

这应该工作。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM