xamarin - 图像大小,在 Xamarin Forms Labs 的图像按钮中的位置

标签 xamarin xamarin.forms

我有以下使用 Xamarin Forms Labs 的 Xaml。图片太小,文字居中。我试图将图像放大一点,但 ImageHeightRequest 属性似乎没有影响。我还尝试了 StackLayout 格式的几种组合,例如 Horizo​​ntalOptions="StartAndExpand"仅用于 StackLayout 以及元素。这会导致按钮被挤压到左侧,并且宽度不足以显示按钮的整个文本。有谁知道如何用更大的图像来实现这一点,并且所有的东西都在左边?我知道图像更大,因为我正在将它从 Windows Phone 移植到 Xamarin,并且相同的图像在 Windows Phone 上更大。我也试过使用常规的 Xamarin Forms Image Button,它呈现相同大小的图像

 <StackLayout Spacing="0"  >

<Label>
  <Label.FormattedText>
    <FormattedString>
      <FormattedString.Spans>
        <Span Text="My Label" ForegroundColor="#5C85FF" Font="Large"/>
      </FormattedString.Spans>
    </FormattedString>
  </Label.FormattedText>
</Label>

<controls:ImageButton Text="Button 1" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image1.png" Orientation="ImageToLeft"  ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ScanProductClicked"  />

<controls:ImageButton Text="Button 2" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image2.png" Orientation="ImageToLeft"  ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ShopProductsClicked"  />

<controls:ImageButton Text="Button 3" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image3.png" Orientation="ImageToLeft"  ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ShoppingListsClicked"  />

<controls:ImageButton Text="Button 4" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image4.png" Orientation="ImageToLeft"  ImageHeightRequest="85" ImageWidthRequest="100" Clicked="LogInClicked"  />

<controls:ImageButton Text="Button 5" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image5.png" Orientation="ImageToLeft"  ImageHeightRequest="85" ImageWidthRequest="100" Clicked="SettingsClicked"  /> </StackLayout>

最佳答案

您可以通过使用 TapGestureRecognizer 使图像可点击来解决此问题。要实现,请执行以下操作:
http://www.c-sharpcorner.com/UploadFile/e04e9a/xamarin-forms-image-button-recipe/

关于xamarin - 图像大小,在 Xamarin Forms Labs 的图像按钮中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27848101/

相关文章:

c# - 如何使用 Xamarin.Forms 将导航按钮添加到主详细信息页面的标题

android - Assets 复制未完成

C# 如何添加一个ListView ClickListener

push-notification - 收到推送通知后确定应用程序是否在前台

c# - 使用 xaml 自定义 View 中的嵌套元素

ios - 更新Firebase程序包后,“InstanceID”不包含“SetApnsToken”的定义

android - Visual Studio 2015 中的 Xamarin MultiDex

c# - 如何在 Xamarin 表单后面的代码中获取 BLE 设备的 mac 地址?

c# - visual studio xamarin.forms 中的秒表将 100 毫秒添加到 react 时间测试

Xamarin Forms - 从模式返回对象