tags:

views:

35

answers:

1

Trying to parse Maplines for an airport. Each airport can have X number of different configurations. In code behind I parse each configuration into a separate collection of custom objects which is data bound to the TabItem below. Currently this TabItem is "Hard Coded" in the XAML body. How do I create a template that I can declare from Code behind so I can create X copies of the TabItem?

Thanks!

<TabItem x:Name="TabTerminalMaplineDefined" Header="Airways Defined">
                                    <Grid x:Name="GridTerminalMaplineDefined" Width="Auto" Height="Auto">

                                        <!--AirwaysFixes Mapping Configuration ListView Start - Lists all the fixes that make up the airway-->
                                        <ListView x:Name="ListViewTerminalMaplineDefined" Grid.RowSpan="2" Width="Auto" FontSize="9">
                                            <ListView.ItemContainerStyle>
                                                <Style TargetType="ListViewItem">
                                                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                                </Style>
                                            </ListView.ItemContainerStyle>
                                            <ListView.View>
                                                <GridView>

                                                    <GridViewColumn Width="60" DisplayMemberBinding="{Binding Path=Name}" >
                                                        <GridViewColumnHeader Click="SortClickAirwaysDefined" Tag="Name" Content="Name" />
                                                    </GridViewColumn>

                                                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Path=X_Y_Beginning}" >
                                                        <GridViewColumnHeader   Content="Segment Start" />
                                                    </GridViewColumn>

                                                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Path=X_Y_Ending}" >
                                                        <GridViewColumnHeader  Content="Segment End" />
                                                    </GridViewColumn>

                                                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Path=Category}" >
                                                        <GridViewColumnHeader Click="SortClickAirwaysDefined" Tag="Category" Content="Category" />
                                                    </GridViewColumn>

                                                </GridView>
                                            </ListView.View>
                                        </ListView>


                                    </Grid>
                                </TabItem>
A: 

Hey there.

Use DataTemplates.

Anvaka
I agree this is the right answer, but do to my own limitations was unable to make it work. The work around to me was to declare a tab item and put it below the tab control in a stack panel. When the user clicks the tab then I bind the appropriate collection to the Tabitem.