【问题标题】:Xamarin Forms loop through list in a GridXamarin Forms 循环遍历网格中的列表
【发布时间】:2020-06-04 07:26:53
【问题描述】:

我有问题。 我创建了以下类:

public class OrderBundles
{
    public int Id { get; set; }
    public NumOfTrades { get; set; }
    public List<Trade> Trades { get; set; }
}

public class Trade
{
    public int Id { get; set; }
    public string Date { get; set; }
    public string Action { get; set; }
    public string Coin { get; set; }
    public decimal Price { get; set; }
    public string ProfitUSDT { get; set; }
}

现在捆绑包的工作方式如下:捆绑包首先包含 SellOrder,然后包含连接到 Sell 的所有 Buy 订单。

使用我想创建以下内容:

现在我已经创建了一个 CollectionView 并附加了一个 ViewModel,但问题是,我如何在 CollectionView 行内循环通过另一个列表,以便我可以使用 RowSpan?

有什么想法吗?

【问题讨论】:

  • “在 CollectionView 内循环,使用 RowSpan”是什么意思?
  • 如您所见,我想要 SellProfit 列上的 RowSpan,它需要覆盖它下面的所有购买。现在,ProfitUSDT 必须重叠的所有行都在交易列表中。这意味着RowSpan of the ProfitUSDT = Trades.Count 如果我只使用 CollectionView 我无法设置 RowSpawn,因为每一行都有自己的网格。

标签: c# xamarin xamarin.forms xamarin.android xamarin.ios


【解决方案1】:

对不起,我误解了你的问题,所以实际上你的问题等于is it possible to create bind on attached property(Grid.RowSpan),xamarin 目前不支持该功能。

参考

Binding to Attached Properties in Xamarin Forms https://github.com/xamarin/Xamarin.Forms/issues/1647

更新

您可以将自定义视图创建为 CollectionView.ItemTemplate ,在方法 BindingContextChanged 中以编程方式设置 rowSpan

   public CustomGrid()
    {
        InitializeComponent();
        this.BindingContextChanged += View1_BindingContextChanged;
    }

    private void View1_BindingContextChanged(object sender, EventArgs e)
    {
        OrderBundles obj = this.BindingContext;

        Grid.SetRowSpan(profitLabel, obj.Trades.Count);
    }

示例链接:https://github.com/ColeXm/GridSample

【讨论】:

  • 但是我可以有多个销售,所以有多个利润栏。这仅适用于 1 次销售
  • 那么有没有办法,实现我想要的?没有其他视图?
  • 你能告诉我完整的 CustomView 是什么样子吗?我的意思是,类型是ViewCell 还是....?
  • 等待我的样品。
  • 我已经在github上传了样例,请查收。
猜你喜欢
  • 2023-03-20
  • 1970-01-01
  • 2013-06-22
  • 2017-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-23
相关资源
最近更新 更多