簡體   English   中英

獲取在CarouselView中點擊的圖片

[英]Get image clicked in CarouselView

我有一個帶有多個圖像的CarouselView,我想獲取被點擊或點擊的內容。 我嘗試添加ax:Name,但是無法在GestureRecognizer中訪問此屬性。

這是我的xaml。 我有4頁,每頁有2張圖片。 我會得到單擊圖像的x:Name或我知道單擊圖像的位置的信息。

<Image Grid.Row="0" Aspect="Fill" Source="{Binding Image1}" x:Name="{Binding ImageName1}" >
            <Image.GestureRecognizers>
                  <TapGestureRecognizer
                          Tapped="ClickImage" />
            </Image.GestureRecognizers>
          </Image>
<Image Grid.Row="1" Aspect="Fill" Source="{Binding Image2}" x:Name="{Binding ImageName2}">
            <Image.GestureRecognizers>
              <TapGestureRecognizer
                      Tapped="ClickImage" />
            </Image.GestureRecognizers>
          </Image>

試試看,看看是否可行:

在xaml中向圖像添加一個classid:

 ClassId ="{Binding Image2}"

並像這樣使用它。 imageString包含唯一的圖像。

 async void ClickImage(object sender, EventArgs eventArgs)
 {
    Image image = (Image)sender;
    string imageString = image.ClassId;
    System.Diagnostics.Debug.WriteLine(imageString);

 }

您可以做的是為每個圖像設置不同的點擊手勢處理程序,例如

<Image Grid.Row="0" Aspect="Fill" Source="{Binding Image1}" x:Name="{Binding ImageName1}" >
            <Image.GestureRecognizers>
                  <TapGestureRecognizer
                          Tapped="ClickImage1" />
            </Image.GestureRecognizers>
          </Image>
<Image Grid.Row="1" Aspect="Fill" Source="{Binding Image2}" x:Name="{Binding ImageName2}">
            <Image.GestureRecognizers>
              <TapGestureRecognizer
                      Tapped="ClickImage2" />
            </Image.GestureRecognizers>
          </Image>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM