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

标签 c# wpf windows microsoft-metro converter

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

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

我是 C# 和 Windows 8 Metro Style 应用编程方面的初学者。

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

XAML:

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

C# 代码隐藏:

Image1.Source = new BitmapImage...

不会工作。编译器会说类似的话

"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不在Visual Studio for Windows(StoreApps)的默认导入列表中,需要先绑定(bind)PresentationCore.dll。)

那么 - 除了使用 Binding 之外,还有什么解决方案可以编辑 Image1.Source 吗?

最佳答案

这应该有效。

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

关于c# - Windows 8 C# : Windows. Ui.Xaml.Media.ImageSource 更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22560144/

相关文章:

c# - MVVM 中的绑定(bind)错误

c++ - 尝试重写 jmp 时出现访问冲突异常

wpf - 在 WPF 中启用滚动条

windows - 使用 golang 创建硬链接(hard link)

windows - 用于 Windows 网络的 Docker

c# - 如何将值设置为 WPF 中的自定义 DataGrid 绑定(bind)列

c# - Process.OutputDataReceived 在哪个线程上引发和处理?

c# - 如何运行一个 c# WinForm 应用程序实例?

c# - 对对象进行递归过滤Linq

c# - MouseEnter WPF 上的发光效果