Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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_Xamarin.forms_Openweathermap - Fatal编程技术网

如何在Xamarin表单头上创建动态图像?

如何在Xamarin表单头上创建动态图像?,xamarin,xamarin.forms,openweathermap,Xamarin,Xamarin.forms,Openweathermap,我正在研究Xamarin表单,其中标题的右侧将有天气温度和天气图标 比如说 纽约太阳城60英尺 我正在使用OpenWeatherAPI获取数据 问题是,我无法在Xamarin表单头上创建动态图像保持器 如何在Xamarin表单头上创建动态图像 附件是一个示例应用程序,我正在工作的基础上的源代码,我从github下载 我不知道你说的“标题”是什么意思,但是如果你想在导航栏中添加图标,你可以通过调用工具栏项来实现。在页面的构造函数中添加(),如下所示: public myPage()

我正在研究Xamarin表单,其中标题的右侧将有天气温度和天气图标

比如说

纽约太阳城60英尺

我正在使用OpenWeatherAPI获取数据

问题是,我无法在Xamarin表单头上创建动态图像保持器

如何在Xamarin表单头上创建动态图像

附件是一个示例应用程序,我正在工作的基础上的源代码,我从github下载


我不知道你说的“标题”是什么意思,但是如果你想在
导航栏中添加图标,你可以通过调用
工具栏项来实现。在页面的构造函数中添加()
,如下所示:

    public myPage()
    {
        InitializeComponent();
        ToolbarItems.Add(new ToolbarItem("Weather", "WeatherIcon.png", async () =>
        {
            //Code to Execute when Icon is tapped
        }));
    }
    public myPage()
    {
        InitializeComponent();

        string weatherIconString = "";
        if(weather.isSunny) // Edit contition however you need
            weatherIconString = "SunnyIcon.png";
        else
            weatherIconString = "CloudyIcon.png";

        ToolbarItems.Add(new ToolbarItem("Weather", weatherIconString));
    }
添加
工具栏项
时,第一个参数是项的名称,第二个参数是将显示在导航栏末端的图像名称,最后一个参数是可选的,它创建了在点击图标时执行的方法

如果您需要图标根据当前天气的不同而有所不同,您可以这样做:

    public myPage()
    {
        InitializeComponent();
        ToolbarItems.Add(new ToolbarItem("Weather", "WeatherIcon.png", async () =>
        {
            //Code to Execute when Icon is tapped
        }));
    }
    public myPage()
    {
        InitializeComponent();

        string weatherIconString = "";
        if(weather.isSunny) // Edit contition however you need
            weatherIconString = "SunnyIcon.png";
        else
            weatherIconString = "CloudyIcon.png";

        ToolbarItems.Add(new ToolbarItem("Weather", weatherIconString));
    }

您必须编写如下自定义渲染器:结果:


你说的“头”是什么意思?导航栏?还是别的什么?标题在XF中没有任何特定含义。@jason,是的,我提到了导航栏。@jason,我已附上示例应用程序的屏幕截图。。在其中可以看到温度场中的天气图标,我需要显示该图标以及城市名称、温度,然后是iconI提到的标题,这就是我们提到Page.Title的地方。我需要在页面标题中包含天气图标。在那里我们可以有一个反箭头图标或汉堡包图标。。。但是,我对静态图像没有问题。我只对动态图像有问题。您提到的标题是导航栏,如果您只想添加图片,您可以使用此代码并删除第三个构造函数,这样在单击它时不会发生任何事情。您的意思是导航栏中可以放置不同的图像吗?如果是这样,您可以编写If语句来更改图片的值。我将编辑我的帖子以显示此内容。这是天气图标..来自openweather..-我需要展示它。。根据当前的天气情况,Xamarin表单工具栏项不支持Uri中的图标。为了在Xamarin表单项目中使用openweathermap.org中的图标,您需要在页面本身而不是在导航栏中显示图标,或者需要下载图像,并将其放入相应的项目图像文件夹中。查看developer.xamarin.com/guides/xamarin-forms/user-interface/images/了解更多信息