我正在处理 Xamarin 表单,我在其中使用了 TapGestureRecognizer 内部图像,现在点击该图像我需要在 c# 中获取图像的源。我怎么得到那个?我这样做的原因是,单选按钮在 Xamarin 表单中不可用,在点击图像时,如果源已选中,我将检查图像的源,然后我需要将源更改为未选中,反之亦然。这是我的 XAML 代码 <Image Scale="0.7" HorizontalOptions="Start" x:Name="radioButton" Source="unchecked.png"> <Image.GestureRecognizers> <TapGestureRecognizer Tapped="radioButton_Clicked"> </TapGestureRecognizer> </Image.GestureRecognizers> </Image>这是我的 C# 代码 private void radioButton_Clicked(object sender, EventArgs e) { var imageSource = "";//get image source here if (imageSource == "Checked.png") { radioButton.Source = "Unchecked.png"; } else { radioButton.Source = "Checked.png"; } }
2 回答

叮当猫咪
TA贡献1776条经验 获得超12个赞
你可以在 radioButton_Clicked 动作上实现这样
private void radioButton_Clicked(object sender, EventArgs e)
{
var imageSource = (Image)sender;//get image source here
var selectedImage = imageSource.Source as FileImageSource;
if (selectedImage.File == "Checked.png")
{
radioButton.Source = "Unchecked.png";
}
else
{
radioButton.Source = "Checked.png";
}
}
或者您可以使用自定义插件支持复选框参考此 https://github.com/XLabs/Xamarin-Forms-Labs
- 2 回答
- 0 关注
- 82 浏览
添加回答
举报
0/150
提交
取消