I have a list of string values (or tags) that I’m wanting to create a DataTemplate within another DataTemplate. For example, say I have an object with strings, ints and a list of strings. The list of strings is the set of tags I’m interested in. For each tag I have a specific DataTemplate I want to use:
<!-- This is the Tag Template-->
<DataTemplate x:Name="TagTemplate">
<Border Background="LightGray">
<TextBlock Text="{Binding TagValue}"/> <!-- This is where I'm not sure how to reference the individual tag-->
</Border>
</DataTemplate>
And the main body of the other DataTemplate would contain the tags like this:
<!-- This is the main Data Template for the overall data-->
<DataTemplate>
<Grid>
<GridView ItemsSource="{Binding Tags}" ItemTemplate="{StaticResource TagTemplate }"/>
<!-- Below is a commented static representation of the tags-->
<!--<TextBlock Text="TAG, TAG, TAG, TAG, TAG" Margin="5, 5, 5, 5"/>-->
</Grid>
<DataTemplate>
The DataBinding for the Tags would be a list of strings List<String> Tags
My problem is I’m not exactly sure how to reference the second binding or if even passing a list of anything is possible from one DataTemplate to another. Is this possible, and if so how?
If your Tags collection is
List<String>then in yourDateTemplatetheDataContextwill be the actual item: so a givenstringand you can bind to the currentDataContextwith the following syntax: