Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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
c#VS 2019 Xamarin:设置嵌入图像源代码的问题_C#_Image_Xamarin - Fatal编程技术网

c#VS 2019 Xamarin:设置嵌入图像源代码的问题

c#VS 2019 Xamarin:设置嵌入图像源代码的问题,c#,image,xamarin,C#,Image,Xamarin,我已经成功地在XAML中创建了一个图像,在网格中,在AbsoluteLayout中 <Image HeightRequest="15" WidthRequest="15" Source="{local:ImageResource ScKWander.Images.UI.arrow_pointer_R.png}" TranslationY="330" TranslationX="15" /> 我试图在代码后面创建图像,以便可以更改代码

我已经成功地在XAML中创建了一个图像,在网格中,在AbsoluteLayout中

<Image HeightRequest="15" WidthRequest="15" 
   Source="{local:ImageResource ScKWander.Images.UI.arrow_pointer_R.png}"                
   TranslationY="330" TranslationX="15"
/>

我试图在代码后面创建图像,以便可以更改代码中的位置。虽然我尝试了几种可能的替代方案,但没有任何效果。下面的代码编译并运行时没有错误。Catch永远不会命中,屏幕上唯一的东西就是用XAML创建的一个图像。我只打算将网格用作容器,但如果需要,我可以使用网格行/列。在UWP中,我使用的是画布

我尝试了几种不同的编码源代码的方法,但都失败了。除了那个,我把所有的都拿了出来

我应该补充一点,我现在有几个Xamarin错误。我想这是新的建筑。我不认为这些影响到这一点。我构建、运行并看到一个由XAML定义的箭头

private void FillGrid()
{
 int iYoffset   = 15;
 int iXoffset   = 15;
 int iYGridsize = 25;
 int iXGridsize = 25;
 try 
   {
   for (int iCount0 = 0; iCount0 < 5; iCount0++)
     {
     for (int iCount1 = 0; iCount1 < 5; iCount1++)
       {
         var thisImage = new Image { Source = ImageSource.FromResource
            ("local:ImageResource ScKWander.Images.UI.arrow_pointer_R.png") };

       //thisImage.TranslationY  = iYoffset + (iCount0 * iYGridsize);
       //thisImage.TranslationX  = iXoffset + (iCount1 * iXGridsize);

         thisImage.HeightRequest = 25;
         thisImage.WidthRequest  = 25;
         gridBoard.Children.Add(thisImage, iCount0 * iYGridsize, iCount1 * iXGridsize);
       }
     }
   }
   catch (Exception e)
   {
   string ex = e.Message;
   }
}
private void FillGrid()
{
int iYoffset=15;
int iXoffset=15;
int=25;
int iXGridsize=25;
尝试
{
对于(int-iCount0=0;iCount0<5;iCount0++)
{
对于(int-iCount1=0;iCount1<5;iCount1++)
{
var thisImage=new Image{Source=ImageSource.FromResource
(“local:ImageResource-ScKWander.Images.UI.arrow\u pointer\u R.png”);
//thisImage.TranslationY=iYoffset+(iCount0*iYGridsize);
//thisImage.TranslationX=iXoffset+(iCount1*iXGridsize);
thisImage.HeightRequest=25;
thisImage.WidthRequest=25;
gridBoard.Children.Add(thisImage,iCount0*iYGridsize,iCount1*iXGridsize);
}
}
}
捕获(例外e)
{
字符串ex=e.消息;
}
}
正确显示了如何执行此操作

var embeddedImage = new Image { 
  Source = ImageSource.FromResource(
    "WorkingWithImages.beach.jpg", 
    typeof(EmbeddedImages).GetTypeInfo().Assembly
  ) };

首先,我真正的问题是没有:

using System.Reflection;
没有IntelliType,但我最终发现需要添加它。 完成后,下面的代码就可以工作了

var thisImage = new Image
{
  Source = ImageSource.FromResource(
    "ScKWander.Images.UI.arrow_pointer_r.png",
    typeof(ImageResourceExtension).GetTypeInfo().Assembly
  ),
  HorizontalOptions = LayoutOptions.Start
};