我的问题是,我有一个带有2个按钮的简单应用程序,当我将它们的text属性设置为该应用程序运行的任何文本以及按钮时。当我删除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>
答案 0 :(得分:0)
似乎按钮不是必需的,为什么不将它们替换为图像:
<?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>