Xamarin.Forms ImageButton 图像填充
Xamarin.Forms ImageButton Image Padding
如何在图像按钮内为源图像制作填充?
更新:
<ImageButton Source="cell_arrow_right.png" IsVisible="{Binding IsNotLeaf}"
VerticalOptions="Center" HorizontalOptions="Center"
WidthRequest="40" HeightRequest="40" Aspect="Fill"
Clicked="ImageButton_Clicked" Margin="0, 0, 15, 0"
BackgroundColor="Transparent" BorderColor="Accent"
BorderWidth="1" Scale="0.9" CornerRadius="5" />
我尝试使用 Padding
,但没有用。它只是移动了源图像。我也尝试编辑 margin
- 仍然没有结果。
现在我刚刚编辑了图像本身,用填充制作了它。但这是个糟糕的决定..(
我怀疑问题实际上是 HorizontalOptions
和 VerticalOptions
,两者都设置为 Center
,这会将 ImageButton
置于其包含元素的中心。
尝试完全删除它们(它们默认为 HorizontalOptions=Fill
,垂直相同)。或者你可以试试:
<ImageButton VerticalOptions="Start" HorizontalOptions="Start" Margin="10" />
这将在 ImageButton
周围留出 10 的边距,并将图像定位在其包含元素的开头(水平和垂直,即顶部和左侧)。
填充表示元素与其子元素之间的距离。
边距表示元素与相邻元素之间的距离。
有一个很好的指南here。
如何在图像按钮内为源图像制作填充?
更新:
<ImageButton Source="cell_arrow_right.png" IsVisible="{Binding IsNotLeaf}"
VerticalOptions="Center" HorizontalOptions="Center"
WidthRequest="40" HeightRequest="40" Aspect="Fill"
Clicked="ImageButton_Clicked" Margin="0, 0, 15, 0"
BackgroundColor="Transparent" BorderColor="Accent"
BorderWidth="1" Scale="0.9" CornerRadius="5" />
我尝试使用 Padding
,但没有用。它只是移动了源图像。我也尝试编辑 margin
- 仍然没有结果。
现在我刚刚编辑了图像本身,用填充制作了它。但这是个糟糕的决定..(
我怀疑问题实际上是 HorizontalOptions
和 VerticalOptions
,两者都设置为 Center
,这会将 ImageButton
置于其包含元素的中心。
尝试完全删除它们(它们默认为 HorizontalOptions=Fill
,垂直相同)。或者你可以试试:
<ImageButton VerticalOptions="Start" HorizontalOptions="Start" Margin="10" />
这将在 ImageButton
周围留出 10 的边距,并将图像定位在其包含元素的开头(水平和垂直,即顶部和左侧)。
填充表示元素与其子元素之间的距离。
边距表示元素与相邻元素之间的距离。
有一个很好的指南here。