【问题标题】:Changing list items color and size in Xamarin.Forms在 Xamarin.Forms 中更改列表项的颜色和大小
【发布时间】:2020-04-17 00:23:21
【问题描述】:

我在 Xamarin.Forms 中有一个使用 C# 填写的列表。将项目添加到列表的代码如下所示:

stockitems_list.ItemsSource = new[] {

                "test 1",
                "test 2",
                "test 3"

            };

结果如下:

如您所见,文本很小且呈红色,而我希望它更大且呈黑色。我发现了一些其他讨论这个问题的话题,但似乎没有什么对我有用。我的 XAML 代码是:

<ContentPage.Content>
        <StackLayout>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
            </Grid>
            <Label x:Name="lbl_apoc_id" Grid.Row="1" HorizontalOptions="CenterAndExpand" FontSize="28" FontAttributes="Bold" TextColor="Black"/>
            <ListView x:Name="stockitems_list" Grid.Row="2" IsEnabled="False"></ListView>
        </StackLayout>
    </ContentPage.Content>

我尝试添加 CellView 并设置 Label 的颜色,但结果根本没有文本(好像 C# 中的列表不再放在那里)。

有人对此有解决方案吗?

问候,甘尼什

【问题讨论】:

标签: c# xaml xamarin.forms xamarin.forms.listview


【解决方案1】:

使用template

<ListView x:Name="stockitems_list" Grid.Row="2" IsEnabled="False">
  <ListView.ItemTemplate>
    <DataTemplate>
      <ViewCell>
        <Label Text="{Binding .}" FontColor="Red" FontSize="Large" />
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多