【问题标题】:How to bind an imageSource from a List of Image items in .NET MAUI如何从 .NET MAUI 中的图像项列表中绑定图像源
【发布时间】:2022-06-18 02:39:20
【问题描述】:

我正在开发一个很快就会有服务器/数据库的应用程序。我想完成列表图像和 xaml 之间的绑定。知道如何进行吗?

 public class Profile : INotifyPropertyChanged
{
    /** --------------------------------------------------------------------
    *                           Properties
    *  --------------------------------------------------------------------
    */
    List<Image> images;
    public List<Image> Images
    {
        get { return images; }
        set { images = value; OnPropertyChanged(nameof(Images)); }
    }
public Profile()
    {
        Images.Add(new Image());
        Images.Add(new Image());
    }


...



<ImageButton Source="{Binding Profile.Images[0].Source}" Aspect="AspectFill" HeightRequest="630"></ImageButton>


    

【问题讨论】:

  • Image Xamarin.Forms.Image,还是别的什么? XF Image 是一个 UI 控件,实际上不应该这样使用。
  • 绑定到字符串列表(包含文件路径)或ImageSources 列表。确保定义一个公共属性public … { get; set; }

标签: c# xaml xamarin.forms binding maui


【解决方案1】:

您可以使用 ObservableCollection 代替 List。它还会在您操作列表时“通知”(即.Add.Remove、...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 2020-10-24
    • 2013-08-22
    • 2019-09-29
    • 2017-11-11
    • 2014-11-17
    • 2022-10-24
    相关资源
    最近更新 更多