2015-11-05 51 views
-1

我有一个简单的XAML代码。它给我一个图像对象:如何在C#中将图像对象制作为Windows Phone 8.1

<Image x:Name="imageIcon" 
     Source="/Assets/Icon.png" 
     Width="160" Height="160" 
     Tapped="imageIcon_Tap" /> 

我想问一下,如何在C#中为我的Windows Phone 8.1编写此代码?

+1

查看文档:https://msdn.microsoft.com/en-us/library/system.drawing.image(v=vs.110).aspx。在询问之前,您应该始终搜索并尝试。 –

+1

谢谢娜塔尼尔!我的解决方案如下: imgIcon.Source = new BitmapImage(new Uri(“ms-appx:///Assets/Icon.png”)); imgIcon.Width =(int)160; imgIcon.Height =(int)160; imgIcon.Tapped + = imageIcon_Tap; grid.Children.Add(imgIcon); – Johnny

回答

1

好吧,

一个尝试了许多解决方案关于纳塔尼尔答案,并诞生了我的解决方案:

imgIcon.Name = "ImgIcon"; 
imgIcon.Source = new BitmapImage(new Uri("ms-appx:///Assets/Icon.png")); 
imgIcon.Width = (int)160; 
imgIcon.Height = (int)160; 
imgIcon.Tapped += imageIcon_Tap; 
grid.Children.Add(imgIcon); 

感谢纳塔尼尔他的意见!

相关问题