【问题标题】:How to set column width in adaptive card so its uniform如何在自适应卡中设置列宽使其统一
【发布时间】:2020-06-01 06:11:42
【问题描述】:

我正在尝试在自适应卡中询问用户信息。但是列大小不同,因此卡片看起来很笨拙。我怎样才能使它看起来很好,每个列集列之间的间隙均匀。我尝试将宽度用作 "Auto""Stretch" 我什至尝试使用 "50px" 和 "100px" 设置宽度,但我没有实现。

请在这方面帮助我。

编辑 1:添加代码

我正在用 C# 创建卡片
这是我的代码

AdaptiveCard card = new AdaptiveCard()
    {
        Body = new List<AdaptiveElement>()
        {
            new AdaptiveColumnSet()
            {
                 Columns = new List<AdaptiveColumn>
                 {
                     new AdaptiveColumn()
                     {
                         Items = new List<AdaptiveElement>()
                         {
                             new AdaptiveTextBlock()
                             {
                                  Text="*First Name",
                                  Weight = AdaptiveTextWeight.Bolder
                              },
                         } ,
                         Width = AdaptiveColumnWidth.Auto
                     },
                      new AdaptiveColumn()
                      {
                           Width = AdaptiveColumnWidth.Auto,
                           Separator = true,
                           Items=new List<AdaptiveElement>()
                            {
                                new AdaptiveTextInput()
                                {
                                    Id = "FirstName",
                                    MaxLength = 300,
                                    Style = AdaptiveTextInputStyle.Text,
                                },
                           }
                      }
                 }
            }, // First Name
            new AdaptiveColumnSet()
            {
                Columns = new List<AdaptiveColumn>
                {
                    new AdaptiveColumn()
                    {
                        Items = new List<AdaptiveElement>()
                        {
                            new AdaptiveTextBlock()
                            {
                                 Text="Middle Name",
                                  Weight = AdaptiveTextWeight.Bolder
                            },
                        }
                    },
                    new AdaptiveColumn()
                    {
                         Width = "stretch",
                         Separator = true,
                         Items=new List<AdaptiveElement>()
                          {
                              new AdaptiveTextInput()
                              {
                                  Id = "MiddleName",
                                  MaxLength = 300,
                                  Style = AdaptiveTextInputStyle.Text,
                              },
                          }
                    }
                 }
            },
            new AdaptiveColumnSet()
            {
                Columns = new List<AdaptiveColumn>
                {
                    new AdaptiveColumn()
                    {
                        Items = new List<AdaptiveElement>()
                        {
                             new AdaptiveTextBlock()
                             {
                                  Text="*Last Name",
                                  Weight = AdaptiveTextWeight.Bolder
                             },
                         }
                    },
                    new AdaptiveColumn()
                    {
                         Width = "stretch",
                         Separator = true,
                         Items=new List<AdaptiveElement>()
                         {
                             new AdaptiveTextInput()
                             {
                                 Id = "LastName",
                                 MaxLength = 300,
                                 Style = AdaptiveTextInputStyle.Text,

                             },

                         }

                    }

                }

            },
            new AdaptiveColumnSet()
            {
               Columns = new List<AdaptiveColumn>
               {
                   new AdaptiveColumn()
                   {
                       Items = new List<AdaptiveElement>()
                       {
                           new AdaptiveTextBlock()
                           {
                               Text="*Date Of Birth",
                               Weight = AdaptiveTextWeight.Bolder
                           },
                       }
                   },
                    new AdaptiveColumn()
                    {
                         Width = "stretch",
                         Separator = true,
                         Items=new List<AdaptiveElement>()
                         {
                             new AdaptiveDateInput()
                             {
                                 Id = "DoB",

                             },

                         }

                    }

               }

            }, // Date Of Birth
        }
    };

【问题讨论】:

  • 你是用Json还是C#来设计自适应卡片?分享您的代码
  • 这是哪个频道的? Facebook、Slack、网络聊天,还有其他什么?
  • 用于网络聊天
  • AdaptiveColumn 类是否有 Size 属性?
  • @StephenOberauer 自适应列没有大小。如果要调整列的大小,可以使用 widthminHeight

标签: botframework adaptive-cards


【解决方案1】:

首先,如果您了解一下模板,您可以更轻松地控制您的卡片。

在这样的代码中创建卡片已经过时了,您仍然可以使用它,但直接使用 json 和模板会更方便。

要回答您的问题,是的,您可以设置像素、拉伸、自动或加权的列宽。类似于这个例子:

        "type": "ColumnSet",
        "columns": [
            {
                "type": "Column",
                "width": 25,
                "horizontalAlignment": "Center",
                "verticalContentAlignment": "Center"
            },
            {
                "type": "Column",
                "width": "stretch"
            }
        ]

您必须将示例中的所有标签列设置为相同的大小。最简单的方法是将它们设置为固定宽度或加权。

如果这不起作用,请确保使用正确的术语,您必须使用小写的“拉伸”,并且当加权时宽度必须是整数,您可以在设计器中尝试这个。自适应卡片本身并不真正关心“拉伸”或“拉伸”,但例如网络聊天有一些问题,卡片版本必须与您的主机支持的相匹配。

最简单的方法,也就是模板再次出现的地方,就是在设计器中设计并试用您的卡片。如果它在设计器中很好,它通常在您要渲染卡的主机中。

希望对你有帮助

【讨论】:

  • 蒂姆在这里。唯一要记住的是,每个渠道接受和使用自适应卡的方式是不同的,因此您的结果(从长远来看)可能而且会有所不同。我知道您说您使用的是完全支持自适应卡片的网络聊天。但是,许多频道不这样做,并将卡转换为另一种格式。 FB,例如将其转换为图像。这也意味着每个属性并不总是像您期望的那样翻译。换句话说,结果是特定于渠道的。仅供参考。
  • 蒂姆,感谢您的回复。我在 C# 中创建卡片,因为如果用户已经有了他们的详细信息,那么我会将它们显示在文本字段中,而不是显示在黑色文本块中。我也尝试向所有列添加相同的宽度属性。 Width = AdaptiveColumnWidth.Stretch 但还是没有改善。
  • 您可以使用模板来完成所有这些操作...添加一个文本框,您可以对其进行预填充...如果您的值为 enpty,则使用占位符。想想在你的例子中,你必须使用固定宽度才能使其正常工作
  • @TimCadenbach 将它们全部设置为相同的宽度会有所帮助。我们需要做的就是为 width 属性设置相同的值。像 Width = "145px" 这样的东西,因为使用 Width = AdaptiveColumnWidth.StretchWidth = AdaptiveColumnWidth.Auto 并没有解决我面临的问题
  • 很好 :) 如果你能接受我的回答,那就太好了:)
猜你喜欢
  • 1970-01-01
  • 2020-08-22
  • 2019-07-22
  • 2021-03-25
  • 2023-03-20
  • 1970-01-01
  • 2012-06-11
  • 2013-02-19
  • 2021-08-03
相关资源
最近更新 更多