如何使用图像中的绑定标签在xamarin表单上显示图像

如何使用图像中的绑定标签在xamarin表单上显示图像

本文介绍了如何使用图像中的绑定标签在xamarin表单上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用xamarin表单尝试通过绑定显示图像...以下一些在线问号已经包含了对此问题的答案https://stackoverflow.com/questions/30850510/how-to-correctly-use-the-image-source-property-with-xamarin-forms似乎无法显示图像...是的,我知道我可以加载通过使用<Image Source="Bud.jpeg"></Image>可以正常工作的图像....但是我想通过绑定显示它.

例如.

xaml
 <Image Source="{Binding imageTest}"></Image>


code

            var imageTest = new Image { Aspect = Aspect.AspectFit };
            imageTest.Source = ImageSource.FromFile("Guinness.jpg");

有人知道为什么吗?谢谢

解决方案

您只能绑定到公共属性

<Image Source="{Binding imageTest}" />

然后在您的代码隐藏中声明一个公共属性

public string imageTest { get; set; }

,然后设置属性值和BindingContext

imageTest = "Guinness.jpg";
this.BindingContext = this;

Using xamarin forms trying to display an image using binding...followed a few online Q's already including the answer on this one https://stackoverflow.com/questions/30850510/how-to-correctly-use-the-image-source-property-with-xamarin-forms just cant seem to get the image to display...yes I knoW I can load the image by using <Image Source="Bud.jpeg"></Image> which works fine....but I would like to display it using binding....

eg..

xaml
 <Image Source="{Binding imageTest}"></Image>


code

            var imageTest = new Image { Aspect = Aspect.AspectFit };
            imageTest.Source = ImageSource.FromFile("Guinness.jpg");

anyone any idea why? thanks

解决方案

You can only bind to public properties

<Image Source="{Binding imageTest}" />

then declare a public property in your code-behind

public string imageTest { get; set; }

and then set the property value and BindingContext

imageTest = "Guinness.jpg";
this.BindingContext = this;

这篇关于如何使用图像中的绑定标签在xamarin表单上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:25