Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xamarin表单动态图像识别器控件_Xamarin_Dynamic_Xamarin.forms - Fatal编程技术网

xamarin表单动态图像识别器控件

xamarin表单动态图像识别器控件,xamarin,dynamic,xamarin.forms,Xamarin,Dynamic,Xamarin.forms,如何通过单击来控制(更改)在xamarin表单中创建的动态图像 Image ggImage = new Image() ggImage.Source = otoTip.imagex ggImage.AutomationId = "seat_" +otoTip.num ggImage.WidthRequest = imageWidth ggImage.HeightRequest = 50 ggImage.VerticalOptions = LayoutOptions.Start ggImage.H

如何通过单击来控制(更改)在xamarin表单中创建的动态图像

Image ggImage = new Image()
ggImage.Source = otoTip.imagex
ggImage.AutomationId = "seat_" +otoTip.num
ggImage.WidthRequest = imageWidth
ggImage.HeightRequest = 50
ggImage.VerticalOptions = LayoutOptions.Start
ggImage.HorizontalOptions = LayoutOptions.Start
ggImage.GestureRecognizers.Add(tapGestureRecognizer)

例如,我只想更改简历来源。

您必须实现TapGestureRecognitor,然后将其添加到图像中

Image ggImage = new Image();
ggImage.Source = otoTip.imagex
ggImage.AutomationId = "seat_" +otoTip.num
ggImage.WidthRequest = imageWidth        
ggImage.HeightRequest = 50;
ggImage.VerticalOptions = LayoutOptions.Start;
ggImage.HorizontalOptions = LayoutOptions.Start;

// your TapGestureRecognizer implementation, this is just a sample...
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) => { ggImage.Source = yourNewSource };
ggImage.GestureRecognizers.Add(tapGestureRecognizer);
为了更改动态创建的图像的每个唯一图像,您可以扩展
otoip
类和

public class OtoTip : INotifyPropertyChanged
{
    public int x { get; set; }
    public int y { get; set; }
    public int num { get; set; }
    public int near { get; set; }
    public int status { get; set; }

    public int yy { get; set; }
    public int xx { get; set; }


    // xx
    private string _imagex;
    public string imagex
    {
        get { return _imagex; }
        set
        {
            _imagex = value;
            OnPropertyChanged(nameof(imagex));
        }
    }

    private string _imageActivex;
    public string imageActivex
    {
        get { return _imageActivex; }
        set
        {
            _imageActivex = value;
            OnPropertyChanged(nameof(imageActivex));
        }
    }


    public event PropertyChangedEventHandler PropertyChanged;

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
您现在必须扩展
getVoyagesData()
,以便将
imageActivex
设置为标准图像

现在,您必须调整TapGestureRecognitor以使用新属性

tapGestureRecognizer.Tapped += (s, e) => 
{ 
    if(ggImage.Source = otoTip.imagex) {
        ggImage.Source = otoTip.imageActivex;
    } 
    else 
    { 
        ggImage.Source = otoTip.imagex;
    }
};

这有帮助吗?

我想做的是更改我在单击动态创建的图像时刚刚单击的图像。谢谢,但是一张图片中有多张图片,因此有可用的巴士计划。例如,我想更改4号座位的来源。我如何提供它?我不明白你在说什么。。。也许多写一点你的项目代码,甚至是一张你想要实现的图片都会有帮助?你所说的一张图片中的一张图片是什么意思。每个图像都有自己的TapGestureRecognitor,因此您只需调整点击事件。对不起,我使用翻译。我想做的是你可以看到上面链接上的图片。在我的照片中没有公共汽车座位计划吗?例如,当我单击图像4时,我想更改空座椅图像=(男性或女性)我的动态图像代码的图像。我原以为它会随automationid更改,但这是不可能的,只是忽略了链接!:(AutomationId用于查找自动化框架的元素(例如用于测试目的)。让我尝试一下,我将更新我的答案。。。