Forms 3.5 pre Bindable StackLayout Question

IrongutIrongut Member ✭✭✭

I'm trying to use the new bindable StackLayout in Forms 3.5 pre to display a list of strings called Tags. I can display them as Labels using:

<StackLayout Orientation="Horizontal" BindableLayout.ItemsSource="{Binding Tags, Mode=OneWay}"/>

The problem is I need to change their text and background colours from the default.

I have tried creating a DataTemplate that contains a Label with the correct colours set but can't figure out how to bind it when my data is just a list of strings.

Best Answer

  • IrongutIrongut ✭✭✭
    Accepted Answer

    I managed to solve my own problem with an empty binding and adding a DataType to my template. :)

    <DataTemplate x:Key="tagsTemplate" x:DataType="x:String">
      <Label Text="{Binding }" TextColor="{StaticResource altTextColor}" BackgroundColor="{StaticResource brandColor}"/>
    </DataTemplate>
    

Answers

  • IrongutIrongut Member ✭✭✭
    Accepted Answer

    I managed to solve my own problem with an empty binding and adding a DataType to my template. :)

    <DataTemplate x:Key="tagsTemplate" x:DataType="x:String">
      <Label Text="{Binding }" TextColor="{StaticResource altTextColor}" BackgroundColor="{StaticResource brandColor}"/>
    </DataTemplate>
    
Sign In or Register to comment.