Windows 8 C#:Windows.Ui.Xaml.Media.ImageSource更改图像
警告Windows API中有两种不同的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
ImageSource
- System.Windows.Media.ImageSource=Windows窗体之一
- Windows.Ui.Xaml.Media.ImageSource=Windows应用商店应用之一
图像的图像
,则使用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"))