将映像添加到 Xamarin 窗体



在Xamarin表单中仍然是新的,我正在尝试添加一个图像。

我打开了一个新的PCL项目,有一个登录表单和一个主页。

我想将 2 张图像添加到主页,但是其中一张图像导致项目崩溃并调用了未处理的异常。

并将其添加到 Android 项目的可绘制库中。

希望得到帮助,谢谢。

附加我的 XAML 名为 tmpImage 的 secound 映像正在解决问题:

<?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>

检查一次图像名称是否正确logo_ComplexInstructions.jpg

我以为.jpg图像不支持Xamarin.Forms(我不完全知道(

点击以下链接

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

最新更新