我的期望: 按钮尺寸为 58x38,其中有一个尺寸为 14x14 的图标。 我尝试的:
1)
<Button
BackgroundColor="{StaticResource cBlue6}"
WidthRequest="58"
HeightRequest="38"
HorizontalOptions="Center"
VerticalOptions="Center"
ImageSource="error.png"
>
</Button>
但我不知道如何调整 error.png 的大小。
2)
<ImageButton
Source="error.png"
WidthRequest="58"
HeightRequest="38"
/>
这里整个按钮是一个图标,但我只想使用大小为 14x14 的图标。
我正在寻找类似的东西:
<Button
BackgroundColor="{StaticResource cBlue6}"
WidthRequest="58"
HeightRequest="38"
HorizontalOptions="Center"
VerticalOptions="Center"
>
<Image Source="error.png" HeightRequest="14" WidthRequest="14"/>
</Button>
但是我无法将任何内容嵌套到 Button 中。出现错误“‘按钮’类型不支持直接内容”。
此选项在 .NET MAUI 按钮中不可用,如果您有兴趣,可以使用我创建的自定义按钮:
签出:https://github.com/FreakyAli/Maui.FreakyControls
然后在前导或尾随空间中添加您想要的尺寸的图像
<freakyControls:FreakyButton
Animation="FadeAndScale"
BackgroundColor="{StaticResource Primary}"
BorderColor="Black"
BusyColor="White"
HorizontalTextAlignment="Center"
LineBreakMode="CharacterWrap"
Text="Edged icon trailing with fade and scale"
TextColor="White"
IconSize="58"
VerticalTextAlignment="Center">
<freakyControls:FreakyButton.TrailingIcon>
<Image Source="calendar.png" HeightRequest="58" WidthRequest ="38" />
</freakyControls:FreakyButton.TrailingIcon>
</freakyControls:FreakyButton>