DotNet Maui:使用ContentLayout时如何调整Button的ImageSource大小?
问题:使用ContentLayout将文本放在ImageSource下方时,如何调整图像大小?
初始代码
<HorizontalStackLayout> <Button MaximumHeightRequest="50" Text="Open" VerticalOptions="Start" ImageSource="file_open.png" ContentLayout="left,50" /> <Button Text="Open file test" ContentLayout="Top,0" VerticalOptions="Start" ImageSource="file_open.png" Command="{Binding DivideBy2Command}" /> <ImageButton x:Name="Toto" MaximumHeightRequest="50" VerticalOptions="Start" Source="file_open.png" Command="{Binding DivideBy2Command}" /> </HorizontalStackLayout>
初始效果

解决方案
结合StackOverflow用户ToolmakerSteve和Alexandar May - MSFT的建议,通过调整Padding、HeightRequest、ContentLayout等属性,可实现图像大小调整并达到预期布局效果。以下是更新后的代码:
<HorizontalStackLayout> <Button Text="Open" HeightRequest="50" VerticalOptions="Start" ImageSource="file_open.png" ContentLayout="left, 0" /> <Button VerticalOptions="Start" Text="Open File" FontSize="10" ImageSource="file_open.png" ContentLayout="Top,-10" Padding="2,-10,2,2" HeightRequest="50" WidthRequest="50" /> <ImageButton VerticalOptions="Start" Source="file_open.png" MaximumHeightRequest="50" /> </HorizontalStackLayout>
优化后效果

内容的提问来源于stack exchange,提问作者Jean-Marc Flamand
相关产品推荐
相关产品推荐

