无法在xamarin.forms中添加图片。

时间:2018-09-01 19:42:43

标签: c# xamarin visual-studio-2017 android-8.1-oreo

Image codeImage = new Image
            {
                Source = "code.jpg",
                Aspect = Aspect.AspectFit,
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions = LayoutOptions.Fill
            };
            StackLayout stackLayout = new StackLayout
            {
                Children =
                {
                    codeImage
                },
                HeightRequest = 1500
            };

我将图像放置在项目的默认位置。我什至尝试右键单击要添加的项目,然后制作一个新的默认图像,然后将该图像替换为我要使用的图像。地狱,我尝试只使用默认图像,该默认图像是在将新图像添加到绘画中绘制几条弯曲的线条,然后再次尝试且仍然没有的情况下生成的。

1 个答案:

答案 0 :(得分:0)

您需要像这样将其添加到内容中:

Image codeImage = new Image
{
    Source = "code.jpg",
    Aspect = Aspect.AspectFit,
    HorizontalOptions = LayoutOptions.End,
    VerticalOptions = LayoutOptions.Fill
};
StackLayout stackLayout = new StackLayout
{
    Children =
    {
        codeImage
    },
    HeightRequest = 1500
};
// If the above isn't working in itself, this will help as final closure:
Content = stackLayout;