哆啦的時(shí)光機(jī)
2022-10-23 15:34:50
我正在處理 Xamarin 表單,我在其中使用了 TapGestureRecognizer 內(nèi)部圖像,現(xiàn)在點(diǎn)擊該圖像我需要在 c# 中獲取圖像的源。我怎么得到那個(gè)?我這樣做的原因是,單選按鈕在 Xamarin 表單中不可用,在點(diǎn)擊圖像時(shí),如果源已選中,我將檢查圖像的源,然后我需要將源更改為未選中,反之亦然。這是我的 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 回答

叮當(dāng)貓咪
TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
你可以在 radioButton_Clicked 動(dòng)作上實(shí)現(xiàn)這樣
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";
}
}
或者您可以使用自定義插件支持復(fù)選框參考此 https://github.com/XLabs/Xamarin-Forms-Labs
- 2 回答
- 0 關(guān)注
- 102 瀏覽
添加回答
舉報(bào)
0/150
提交
取消