Q:

data-bind list within a list, uwp + xaml

I have the following model:
public class TableData
{
    [JsonProperty(PropertyName = "objectsDetected")]
    public List<ObjectsDetected> ObjectsDetected { get; set; }

    [JsonProperty(PropertyName = "file_name_at_upload")]
    public int File_Name_At_Upload { get; set; }
}

public class ObjectsDetected
{
    [JsonProperty(PropertyName = "className")]
    public string className { get; set; }

    [JsonProperty(PropertyName = "score")]
    public double score { get; set; }
}

Im getting my data from an api call:
        var request = (HttpWebRequest)WebRequest.Create("http://localhost:58941/api/data");
        request.Method = "GET";
        request.ContentType = "application/json";
        WebResponse response = await request.GetResponseAsync();

        if (response != null)
        {
            string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            List<TableData> myDeserializedObjList = (List<TableData>)JsonConvert.DeserializeObject(responseString, typeof(List<TableData>));
            cosmosData.ItemsSource = myDeserializedObjList;

        }

This is the XAML code:
    <StackPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200"/>
                <ColumnDefinition Width="200"/>
            </Grid.ColumnDefinitions>

            <TextBlock Grid.Column="0" Text="Navn på billede" Foreground="Black" FontSize="20" FontWeight="Bold"/>
            <TextBlock Grid.Column="2" Text="Kategori fundet" Foreground="Black" FontSize="20" FontWeight="Bold"/>
        </Grid>
            <GridView x:Name="cosmosData"
                      ItemClick="cosmosData_ItemClick"
                      IsItemClickEnabled="True"
                      IsSwipeEnabled="true"
                      SelectionMode="Single">
                <GridView.ItemTemplate>
                <DataTemplate x:DataType="local:TableData">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="200"/>
                            <ColumnDefinition Width="200"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Column="0" Text="{x:Bind File_Name_At_Upload}" />
                        <TextBlock Grid.Column="2" Text="{x:Bind ObjectsDetected.className}"/>

                    </Grid>
                </DataTemplate>

            </GridView.ItemTemplate>
            </GridView>
    </StackPanel>

I want to display in the user interface TableData and ObjectsDetected.classname in the same table, but i cannot access ObjectsDetected.classname? How can i achieve this?         

A:

As you want to display multiple class names per TableData, you're going to need to either created a composite string of all the class names or use an ItemsControl to display them. The latter is not as performant, but is also easily doable purely in XAML like so:
<GridView x:Name="cosmosData" ItemClick="cosmosData_ItemClick" IsItemClickEnabled="True" IsSwipeEnabled="true" SelectionMode="Single">
<GridView.ItemTemplate>
    <DataTemplate x:DataType="local:TableData">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200"/>
                <ColumnDefinition Width="200"/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" Text="{x:Bind File_Name_At_Upload}" />
            <ItemsControl Grid.Column="1" ItemsSource="{x:Bind ObjectsDetected}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding className}"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
    </DataTemplate>
</GridView.ItemTemplate>

As an alternate option, you could add another property on your TableData model like so:
public class TableData
{
    [JsonProperty(PropertyName = "objectsDetected")]
    public List<ObjectsDetected> ObjectsDetected { get; set; }

    [JsonProperty(PropertyName = "file_name_at_upload")]
    public int File_Name_At_Upload { get; set; }

    [JsonIgnore]
    public string ClassNames => String.Join(",", ObjectsDetected.Select(o => o.className));
}

And then in your original code, bind to the ClassNames property instead. (This will comma join the values, but you could use \n instead of , to put each one on it's own line). You'd also need to set TextWrapping in the TextBlock

