2017-07-12 1 views
1

noch neu in Xamarin Formen Ich versuche ein Bild hinzuzufügen.Hinzufügen eines Bildes zu Xamarin Formen

Ich habe ein neues PCL-Projekt mit einem Login-Formular und einer Hauptseite geöffnet.

Ich möchte auf der Hauptseite die 2 Bilder hinzufügen, aber eines der Bilder verursachen das Projekt zum Absturz und nannte eine unbehandelte Ausnahme.

das ist im Projekt. und fügen Sie es auch der drawable libery des Android-Projekts hinzu.

hoffe, Hilfe zu bekommen, danke.

meine XAML genannt secound Bild Anbringen tmpImage tut das Problem:

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     xmlns:local="clr-namespace:ComplexInstruction" 
     x:Class="ComplexInstruction.MainPage"> 

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="0,1*"></RowDefinition> 
     <RowDefinition Height="1*"></RowDefinition> 
     <RowDefinition Height="0.1*"></RowDefinition> 
     <RowDefinition Height="1*"></RowDefinition> 
     <RowDefinition Height="0.1*"></RowDefinition> 
     <RowDefinition Height="1*"></RowDefinition> 
     <RowDefinition Height="0.1*"></RowDefinition> 
     <RowDefinition Height="1*"></RowDefinition> 
     <RowDefinition Height="0.1*"></RowDefinition> 
     <RowDefinition Height="1*"></RowDefinition> 
     <RowDefinition Height="0.1*"></RowDefinition> 
     <RowDefinition Height="1*"></RowDefinition> 
     <RowDefinition Height="0.1*"></RowDefinition> 
    </Grid.RowDefinitions> 


    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="0.1*"></ColumnDefinition> 
     <ColumnDefinition Width="1*"></ColumnDefinition> 
     <ColumnDefinition Width="0.1*"></ColumnDefinition> 
     <ColumnDefinition Width="1*"></ColumnDefinition> 
     <ColumnDefinition Width="0.1*"></ColumnDefinition> 
    </Grid.ColumnDefinitions> 


    <Image Aspect="Fill" Source="logo_ComplexInstructions.jpg" 
     RelativeLayout.WidthConstraint= 
      "{ConstraintExpression Type=RelativeToParent, Property=Width}" 
     RelativeLayout.HeightConstraint= 
      "{ConstraintExpression Type=RelativeToParent, Property=Height}" Opacity="0.3" Grid.ColumnSpan="5" Grid.Row="0" Grid.RowSpan="2" /> 




     <Image x:Name="tmpImage" Aspect="Fill" Source="SHA_6620.jpg" 
     RelativeLayout.WidthConstraint= 
      "{ConstraintExpression Type=RelativeToParent, Property=Width}" 
     RelativeLayout.HeightConstraint= 
      "{ConstraintExpression Type=RelativeToParent, Property=Height}" 
Grid.ColumnSpan="5" Grid.Row="3" Grid.RowSpan="8" /> 

</Grid> 


</ContentPage> 
+0

Was sind die Abmessungen (Breite und Höhe in Pixel) Ihre Bilder? –

+0

Was ist die genaue Ausnahme? – Jason

+0

Ist Build Action auf 'AndroidResource' gesetzt? –

Antwort

1

Überprüfen Sie Ihr Bild Name einmal logo_ComplexInstructions.jpg es richtig ist oder nicht

Und

Ich dachte . jpg Bilder unterstützen nicht Xamarin.Forms (ich weiß nicht exatactly)

Folgen Sie unten l Tinten

https://developer.xamarin.com/api/type/System.Drawing.Imaging.ImageFormat/

+0

Sieht so aus als ob sie .jpg in den Entwicklerdokumenten verwenden, aber ich habe mich selbst nicht getestet: https: // developer.xamarin.com/guides/xamarin-forms/user-interface/images/ – Joe