【问题标题】:how to display an image on xamarin forms using binding tag from image如何使用图像中的绑定标签在 xamarin 表单上显示图像
【发布时间】:2019-11-29 23:25:34
【问题描述】:

使用 xamarin 表单尝试使用绑定显示图像...跟随一些在线 Q 已经包括这个答案 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");

有人知道为什么吗?谢谢

【问题讨论】:

    标签: c# xamarin xamarin.forms


    【解决方案1】:

    您只能绑定到公共属性

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

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

    public string imageTest { get; set; }
    

    然后设置属性值和BindingContext

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-03
      • 2020-04-01
      • 2021-12-07
      • 2017-09-06
      • 2019-08-17
      • 2020-06-10
      • 2021-01-08
      • 1970-01-01
      相关资源
      最近更新 更多