Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 8 C#:Windows.Ui.Xaml.Media.ImageSource更改图像_C#_Wpf_Windows_Microsoft Metro_Converter - Fatal编程技术网

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

Windows 8 C#:Windows.Ui.Xaml.Media.ImageSource更改图像,c#,wpf,windows,microsoft-metro,converter,C#,Wpf,Windows,Microsoft Metro,Converter,警告Windows API中有两种不同的ImageSource System.Windows.Media.ImageSource=Windows窗体之一 Windows.Ui.Xaml.Media.ImageSource=Windows应用商店应用之一 我是C#和Windows8 Metro风格应用程序编程的初学者 但是,如果要编辑图像的图像,则使用BitmapImage的“旧”方法将不起作用: XAML: 不行。编译器会说 “System.Windows.Media.Imaging.Bit

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

  • System.Windows.Media.ImageSource=Windows窗体之一
  • Windows.Ui.Xaml.Media.ImageSource=Windows应用商店应用之一
我是C#和Windows8 Metro风格应用程序编程的初学者

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

XAML:

不行。编译器会说

“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
s之外,还有什么办法可以编辑Image1.Source吗?

这应该是可行的

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

ConvertFromString
位于TypeConverter.dll中,它仅位于旧版本System.dll中,较新版本(我使用4.5.1)没有该TypeConverter:(我已更新了答案。我应该记得ImageSourceConverter在WPF和WP7上工作,但在WinRT中不工作。BitmapImage肯定在RT上工作,假设“”是一个有效的url。谢谢,这很有效。对于本地文件,我使用了
(new System.Uri(“ms appx:/Assets/pic.png”)
Image1.Source = new BitmapImage...
Image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new System.Uri("http://image.source.de"))