Xamarin Forms列表视图设计

huangapple go评论112阅读模式
英文:

Xamarin Forms list view design

问题

你好,以下是您要翻译的内容:

"如何实现以下操作,这是许多项目的列表。但挑战在于将每个项目添加到该气泡中,具有以下设计。

欢迎任何想法"

请问您还需要其他帮助吗?

英文:

How could I achieve the following , it is a list of many items . but the challenge is to add each item into that buble with the following design.

Open to any ideas

Xamarin Forms列表视图设计

答案1

得分: 1

以下是您要翻译的内容:

正如Jason所说,FlexLayout是一个不错的方法。如果您想要将圆角添加到按钮,可以使用BorderRadius属性。

Xaml:

<ContentPage.Resources>
    <Style TargetType="FlexLayout">
        <Setter Property="AlignItems" Value="Start" />
        <Setter Property="Direction" Value="Row" />
        <Setter Property="Wrap" Value="Wrap" />
    </Style>
    <Style TargetType="Button">
        <Setter Property="BackgroundColor" Value="Blue" />
        <Setter Property="TextColor" Value="White" />
        <Setter Property="Margin" Value="5" />
    </Style>
</ContentPage.Resources>

<FlexLayout AlignContent="Start">
    <Button BorderRadius="25" Text="WIFI" />
    <Button BorderRadius="25" Text="PROJECTOR" />
    <Button BorderRadius="25" Text="APPLE TV" />
    <Button BorderRadius="25" Text="COUCH" />
    <Button BorderRadius="25" Text="WHITEBOARD" />
    <Button BorderRadius="25" Text="CONFERENCE BRIDGE" />
</FlexLayout>

更新:

Xaml:

<ContentPage.Resources>
    <Style TargetType="FlexLayout">
        <Setter Property="AlignItems" Value="Start" />
        <Setter Property="Direction" Value="Row" />
        <Setter Property="Wrap" Value="Wrap" />
        <Setter Property="AlignContent" Value="Start" />
    </Style>
    <Style TargetType="Button">
        <Setter Property="BackgroundColor" Value="Blue" />
        <Setter Property="TextColor" Value="White" />
        <Setter Property="Margin" Value="5" />
    </Style>
</ContentPage.Resources>
<FlexLayout BindableLayout.ItemsSource="{Binding List}">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <Button BorderRadius="25" Text="{Binding Value}" />
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</FlexLayout>

xaml.cs:

public partial class MainPage : ContentPage
{
    public List<Values> List { get; set; }
    public MainPage()
    {
        InitializeComponent();

        List = new List<Values>()
        {
             new Values(){ Value="WIFI"},
             new Values(){ Value="PROJECTOR"},
             new Values(){ Value="APPLE TV"},
             new Values(){ Value="COUCH"},
             new Values(){ Value="WHITEBOARD"},
             new Values(){ Value="CONFERENCE BRIDGE"},
        };
        BindingContext = this;
    }
}

public class Values
{
    public string Value { get; set; }
}

希望这对您有所帮助!

英文:

As Jason said, FlexLayout is a good way. And if you want to add rounded corners to a button, you could use BorderRadius property.

Xaml:

&lt;ContentPage.Resources&gt;
    &lt;Style TargetType=&quot;FlexLayout&quot;&gt;
        &lt;Setter Property=&quot;AlignItems&quot; Value=&quot;Start&quot; /&gt;
        &lt;Setter Property=&quot;Direction&quot; Value=&quot;Row&quot; /&gt;
        &lt;Setter Property=&quot;Wrap&quot; Value=&quot;Wrap&quot; /&gt;
    &lt;/Style&gt;
    &lt;Style TargetType=&quot;Button&quot;&gt;
        &lt;Setter Property=&quot;BackgroundColor&quot; Value=&quot;Blue&quot; /&gt;
        &lt;Setter Property=&quot;TextColor&quot; Value=&quot;White&quot; /&gt;
        &lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot; /&gt;
    &lt;/Style&gt;
&lt;/ContentPage.Resources&gt;

&lt;FlexLayout AlignContent=&quot;Start&quot;&gt;
    &lt;Button BorderRadius=&quot;25&quot; Text=&quot;WIFI&quot; /&gt;
    &lt;Button BorderRadius=&quot;25&quot; Text=&quot;PROJECTOR&quot; /&gt;
    &lt;Button BorderRadius=&quot;25&quot; Text=&quot;APPLE TV&quot; /&gt;
    &lt;Button BorderRadius=&quot;25&quot; Text=&quot;COUCH&quot; /&gt;
    &lt;Button BorderRadius=&quot;25&quot; Text=&quot;WHITEBOARD&quot; /&gt;
    &lt;Button BorderRadius=&quot;25&quot; Text=&quot;CONFERENCE BRIDGE&quot; /&gt;
&lt;/FlexLayout&gt;

Xamarin Forms列表视图设计

Updated:

Xaml:

  &lt;ContentPage.Resources&gt;
    &lt;Style TargetType=&quot;FlexLayout&quot;&gt;
        &lt;Setter Property=&quot;AlignItems&quot; Value=&quot;Start&quot; /&gt;
        &lt;Setter Property=&quot;Direction&quot; Value=&quot;Row&quot; /&gt;
        &lt;Setter Property=&quot;Wrap&quot; Value=&quot;Wrap&quot; /&gt;
        &lt;Setter Property=&quot;AlignContent&quot; Value=&quot;Start&quot; /&gt;
    &lt;/Style&gt;
    &lt;Style TargetType=&quot;Button&quot;&gt;
        &lt;Setter Property=&quot;BackgroundColor&quot; Value=&quot;Blue&quot; /&gt;
        &lt;Setter Property=&quot;TextColor&quot; Value=&quot;White&quot; /&gt;
        &lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot; /&gt;
    &lt;/Style&gt;
&lt;/ContentPage.Resources&gt; 
&lt;FlexLayout BindableLayout.ItemsSource=&quot;{Binding List}&quot;&gt;
    &lt;BindableLayout.ItemTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;Button BorderRadius=&quot;25&quot; Text=&quot;{Binding Value}&quot; /&gt;
        &lt;/DataTemplate&gt;
    &lt;/BindableLayout.ItemTemplate&gt;
&lt;/FlexLayout&gt;

xaml.cs

public partial class MainPage : ContentPage
{

    public List&lt;Values&gt; List { get; set; }
    public MainPage()
    {
        InitializeComponent();

        List = new List&lt;Values&gt;()
        {
             new Values(){ Value=&quot;WIFI&quot;},
             new Values(){ Value=&quot;PROJECTOR&quot;},
             new Values(){ Value=&quot;APPLE TV&quot;},
             new Values(){ Value=&quot;COUCH&quot;},
             new Values(){ Value=&quot;WHITEBOARD&quot;},
             new Values(){ Value=&quot;CONFERENCE BRIDGE&quot;},
        };
        BindingContext = this;

    }
}
public class Values
{
    public string Value { get; set; }
}

Xamarin Forms列表视图设计

huangapple
  • 本文由 发表于 2020年1月6日 23:20:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614621.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定