Type image not found error in Xamarin.Forms

2019-07-30 18:12发布

问题:

I have a Forms application, and have ContentPage XAML form.

I try to add an image to this Grid but this code gives me the error Type image not found.
Note : I had been added this image under Recources and tried also on the root folder.

How can I fix this?

Note2: I had been by right clicked the project and had added image to project.

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>

  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <Button Text="1" Grid.Row="0" Grid.Column="0" />
  <image Grid.Row="0" Grid.Column="1" source="image2.png"></image>
  <Button Text="3" Grid.Row="0" Grid.Column="2" />
</Grid>

回答1:

XML (and thus XAML) is case-sensitive, so make it <Image> and </Image>.

Like this:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>

  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <Button Text="1" Grid.Row="0" Grid.Column="0" />
  <Image Grid.Row="0" Grid.Column="1" Source="image2.png"></Image>
  <Button Text="3" Grid.Row="0" Grid.Column="2" />
</Grid>