Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 向按钮添加图像属性时为什么Xamarin应用程序不运行_Xaml_Xamarin - Fatal编程技术网

Xaml 向按钮添加图像属性时为什么Xamarin应用程序不运行

Xaml 向按钮添加图像属性时为什么Xamarin应用程序不运行,xaml,xamarin,Xaml,Xamarin,我的问题是,我有一个简单的应用程序,当我将其文本属性设置为应用程序运行的任何文本和按钮时,它有两个按钮。当我删除text属性并添加图像时,应用程序不会运行,但不会引发任何异常或错误 注意:我已将该按钮的图标图像附加到Android.Resources.Drawable 这是XAML代码: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/form

我的问题是,我有一个简单的应用程序,当我将其文本属性设置为应用程序运行的任何文本和按钮时,它有两个按钮。当我删除text属性并添加图像时,应用程序不会运行,但不会引发任何异常或错误

注意:我已将该按钮的图标图像附加到Android.Resources.Drawable

这是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"
             x:Class="PhotoGallery.Gallery"
             BackgroundColor="Black">
    <AbsoluteLayout>
        <Image Source="https://picsum.photos/1920/1080" x:Name="pic" Aspect="AspectFit" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"></Image>
        <ActivityIndicator IsRunning="{Binding Source={x:Reference pic} , Path=IsLoading}" AbsoluteLayout.LayoutBounds="0.5,0.1,100,100" AbsoluteLayout.LayoutFlags="PositionProportional"></ActivityIndicator>
        <Button Image="left.png" x:Name="btnPrevious" AbsoluteLayout.LayoutBounds="0.05 , 0.05 , 150 , 50" AbsoluteLayout.LayoutFlags="PositionProportional"></Button>
        <Button Image="right.png" x:Name="btnNext" AbsoluteLayout.LayoutBounds="0.95 , 0.05 , 150 , 50" AbsoluteLayout.LayoutFlags="PositionProportional"></Button>
    </AbsoluteLayout>
</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"
             x:Class="PhotoGallery.Gallery"
             BackgroundColor="Black">
    <AbsoluteLayout>
        <Image Source="https://picsum.photos/1920/1080" x:Name="pic" Aspect="AspectFit" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"></Image>
        <ActivityIndicator IsRunning="{Binding Source={x:Reference pic} , Path=IsLoading}" AbsoluteLayout.LayoutBounds="0.5,0.1,100,100" AbsoluteLayout.LayoutFlags="PositionProportional"></ActivityIndicator>
        <Image Source="left.png" x:Name="btnPrevious" AbsoluteLayout.LayoutBounds="0.05 , 0.05 , 150 , 50" AbsoluteLayout.LayoutFlags="PositionProportional">
            <Image.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnPreviousImageTapped"  />
            </Image.GestureRecognizers>
        </Image>
        <Image Source="right.png" x:Name="btnNext" AbsoluteLayout.LayoutBounds="0.95 , 0.05 , 150 , 50" AbsoluteLayout.LayoutFlags="PositionProportional">
            <Image.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnNextImageTapped"  />
            </Image.GestureRecognizers>
        </Image>
    </AbsoluteLayout>
</ContentPage>


我似乎对Android.Resources附带的图像有问题,当我尝试您的解决方案时,应用程序运行,但left.png和right.png没有出现。关于我的错误有什么建议吗?选项1:如果您从项目外部添加了图像,请右键单击图像并选择“包括”,以确保已将图像包括在可绘制文件夹中。选项2:从文件夹中删除现有图像,然后右键单击drawable->add existing item->add your image,再次从项目中添加图像。我已经通过选项2添加了它们。我甚至尝试在主解决方案中包含图像,但仍然遇到相同的问题,只是为了测试,使用
StackLayout
而不是
AbsoluteLayout
设计元素,可能是
AbsoluteLayout。LayoutBounds
不在正确的位置,因此图像没有显示。同样的问题,我厌倦了寻找和尝试。当我将Source属性设置为url时,它可以正常工作,但硬盘上的图像甚至不包括在解决方案中