gpt4 book ai didi

xaml - 如何在Xamarin Forms中用图像填充按钮?

转载 作者:行者123 更新时间:2023-12-03 13:23:52 25 4
gpt4 key购买 nike

我正在尝试用Button填充Image。该按钮位于网格内。问题是图像没有完全填满按钮。我也尝试过使用ImageButton控件。

这是我建立自己的U.I的方式:

<Grid Grid.Row="1" Grid.Column="1" x:Name="VotingGrid" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="45*" />
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="45*" />
</Grid.ColumnDefinitions>

<Button Grid.Row="0" Grid.Column="0" Image="yay.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<Button Grid.Row="0" Grid.Column="2" Image="meh.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</Grid>


当前看起来像下面的图像,但是我想对图像进行填充。

enter image description here

任何帮助将不胜感激!

最佳答案

尝试放置图像而不是按钮。

您可以使用Tap Gesture Gesture Recognizer进行点击事件。

试试这样的事情:

<Image Source="tapped.jpg">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnTapGestureRecognizerTapped" />
</Image.GestureRecognizers>
</Image>


事件处理程序的代码

void OnTapGestureRecognizerTapped(object sender, EventArgs args) {
var imageSender = (Image)sender;
// Do something
DisplayAlert ("Alert", "Tap gesture recoganised", "OK");
}




请参阅: Adding a Tap Gesture Gesture Recognizer

关于xaml - 如何在Xamarin Forms中用图像填充按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37294834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com