0

我正在使用 Devexpress 的 CardView,我正在像这样绑定到数据库:

    var cardView = Html.DevExpress().CardView(settings =>
    {
      settings.Name = "MyCardView";
    }

    @cardView.BindToEF(string.Empty, string.Empty, (s, e) =>
    {
      e.QueryableSource = Helper.CustomerData();
    }).GetHtml()

现在我可以通过执行以下操作将链接添加到卡片顶部:

    var cardView = Html.DevExpress().CardView(settings =>
    {
      settings.Name = "MyCardView";
      settings.CardLayoutProperties.Items.AddGroupItem(g =>
      {
          g.ColSpan = 1;
          g.ShowCaption = DefaultBoolean.False;
          g.GroupBoxDecoration = GroupBoxDecoration.None;

          var cmdLayoutItem = new CardViewCommandLayoutItem();
          cmdLayoutItem.HorizontalAlign = FormLayoutHorizontalAlign.Right;

          var publicUrlButton = new CardViewCustomCommandButton();
          publicUrlButton.ID = "Link123";
          publicUrlButton.Text = "My Funny Url";

          cmdLayoutItem.CustomButtons.Add(publicUrlButton);
          g.Items.Add(cmdLayoutItem);
        });

        settings.Columns.Add(c =>
        {
            c.FieldName = "Id";
            c.Caption = "Id";
            c.ReadOnly = true;
            c.Visible = false;
        });

        settings.Columns.Add(c =>
        {
            c.FieldName = "IsOpen";
            c.Caption = "IsOpen";
            c.ReadOnly = true;
            c.Visible = false;
        });
    }

    @cardView.BindToEF(string.Empty, string.Empty, (s, e) =>
    {
      e.QueryableSource = Helper.CustomerData();
    }).GetHtml()

Helper.CustomerData()返回IQueryable<CustomerData>一个. 现在想象我的表CustomerData有一个名为IsOpen. 我怎样才能显示publicUrlButton只有当值为IsOpen真时?

4

1 回答 1

0

经过几个小时的挖掘终于找到了解决方案。基本上,您可以使用以下事件来控制行为:

        settings.CustomButtonInitialize = (s, e) =>
        {
            var cv = s as MVCxCardView;
            if (cv == null)
            {
                return;
            }

            var isOpen = cv.GetCardValues(e.VisibleIndex, "IsOpen");
            if (!isOpen)
            {
                if (e.ButtonID == "Link123")
                {
                    e.Visible = DefaultBoolean.False;
                }
            }
        };
于 2020-11-07T10:53:11.347 回答