【问题标题】:Xamarin Forms XAML Image control has quit workingXamarin Forms XAML 图像控件已停止工作
【发布时间】:2019-03-30 17:13:50
【问题描述】:

我有一个显示图像的工作应用程序。我启动了一个新应用程序并复制了代码,但这个新应用程序不显示图像。很困惑,我已经尝试了很多很多东西来调试它。我最终制作了一个只有图像控件的普通新项目。像往常一样,我使用 Add Existing Item 将图片添加到项目中。我确认图像在那里。它不显示图像。我在解决方案资源管理器中注意到一些不同的东西。在解决方案下,第一个项目下列出了依赖项。这是新的。我以前的应用程序从未有过。现在我创建的每个新项目都有它。我还注意到图像的属性是无构建操作。我尝试将其更改为内容,但这没有帮助。在这一点上,我感到困惑和卡住。 Visual Studio 有什么变化吗?这是图像测试 XAML。

<?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:ImageTest"
             x:Class="ImageTest.MainPage">

    <StackLayout>
        <!-- Place new controls here -->
        <Image Source="gr8oz.png" />
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
    </StackLayout>

</ContentPage>

正如我所说,我有一个已发布的工作应用程序。我将此代码复制到一个新应用程序中,但它不起作用。在我的调查中,我发现图像控件不再适合我。

<?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:OFamV2"
             Style="{StaticResource MyContentPage}"
             x:Class="OFamV2.MainPage"
             Title="Main Menus">
    <ScrollView>
    <StackLayout>
        <Button x:Name="TreeButton"
                    Text="Don and Iola Osborne"
                    VerticalOptions="Start"
                    Style="{StaticResource MyButtons}"
                    Clicked="TreeButton_Clicked" />
        <Button x:Name="IndianNamesButton" 
                    Text="Indian Names"
                    VerticalOptions="Start"
                    Style="{StaticResource MyButtons}"
                    Clicked="IndianNamesButton_Clicked" />
        <Button x:Name="NextPageButton" 
                    Text="Indian Potpourri"
                    VerticalOptions="Start"
                    Style="{StaticResource MyButtons}"
                    Clicked="NextPageButton_Clicked" />
        <Button x:Name="OldPhotos"
                    Text="Old Photos"
                    VerticalOptions="Start"
                    Style="{StaticResource MyButtons}"
                    Clicked="OldPhotos_Clicked" />
        <Button x:Name="ReunionButton" 
                    Text="Family Reunion"
                    VerticalOptions="Start"
                    Style="{StaticResource MyButtons}"
                    Clicked="ReunionButton_Clicked"
                    />
            <StackLayout Orientation="Horizontal">
                <Image                  
                    Source="Photos/gr8oz.png"
                    Style="{StaticResource MyImage}"
                    Margin="0,30,0,0"
                    Aspect="AspectFit"
                    HorizontalOptions="End"
                    />
                <Image
                    Source = "Photos/logo.bmp" 
                    Style="{StaticResource MyImage}"
                    Margin="150,0,0,0"
                    HeightRequest="200"
                    WidthRequest="200"
                    HorizontalOptions="End"/>
            </StackLayout>

        </StackLayout>
    </ScrollView>
</ContentPage>

我已经搜索并阅读了我能找到的所有内容(是的,我已经阅读了有关 Image 类的 Microsoft 文档)。

我也很好奇为什么 Dependencies 突然出现在 Shared Project 文件夹中。这也是新的。我该如何解决它们?见截图。 Dependencies under OFamV2.

我卸载了 Visual Studio,删除了文件夹,重新安装了 Visual Studio Community 2017 版本 15.8.8,问题仍然存在,即使是新项目。

对于选项,我选择跨平台/移动应用程序/平台:Android 和 UWP/代码共享:.Net 标准。

【问题讨论】:

  • 您在创建新项目时选择了哪些选项?对于 Xamarin.Forms 共享代码,始终可以选择使用“共享项目”或“可移植类库项目”(PCL)。 PCL 项目已替换为具有 Dependencies 伪文件夹的 .NET Standard 项目。您是否通常将图像文件放在 shred 项目或应用程序特定项目中。我需要查看一个旧的“工作”应用和一个新的“非工作”应用,以准确了解您之前在做什么和现在在做什么。
  • 您阅读过有关使用图像的文档吗?位置和构建操作取决于平台。 docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/…
  • 从您的信息中很难判断,但是您是否正确添加了图像?确保将它们添加到平台项目中的正确文件夹并正确设置构建操作。

标签: image xamarin.forms


【解决方案1】:

设置图片显示你可以看到here,我想你已经用过了。

所以重新加载你的项目,然后重建它,你可以试试这个。

更多信息:

  1. Here 是关于图像显示的类似讨论。

  2. 建议最好不要从其他项目中复制有关视图的代码,它们可能会导致一些你不知道的问题。

【讨论】:

    猜你喜欢
    • 2022-06-17
    • 2019-10-25
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 2021-01-15
    • 1970-01-01
    • 2014-05-22
    相关资源
    最近更新 更多