1
(Level-1)
Scalar ---value
Enum  ---value
String ---Value
Boolean ---value
Array
    (Level-2)
    -Array  
        (Level-3)
        -Scalar ---value
        -Enum  ---value
        -String ---Value
        -Boolean ---value
    -Scalar ---value
    -Enum  ---value
    -String ---Value
    -Boolean ---value

I have to display a treeview as shown in above tree. The level 1 items are enum,scalar,boolean,string,Array object. I have written templateSelector to select different template for each level 1 objects. I am able to write data template for level 1 types. But how to write template for "Array Type" because it again contains level 1 items as its items(level-2). same issue for level-3. Only 3 level are allowed.

<local:ParameterTemplateSelector x:Key="ParameterTemplateSelector"></local:ParameterTemplateSelector>
    <DataTemplate x:Key="ScalarTemplate">
        <StackPanel Orientation="Horizontal">
            <Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>
            <TextBox Text="{Binding Value.Item.Value}" Width="100" TextAlignment="Center"></TextBox>
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Key="EnumTemplate">
        <StackPanel Orientation="Horizontal">
            <Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>
            <TextBox Text="{Binding Value.Item.Value}" Width="100" TextAlignment="Center"></TextBox>
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Key="StringTemplate">
        <StackPanel Orientation="Horizontal">
            <Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>
            <TextBox Text="{Binding Value.Item}" Width="100" TextAlignment="Center"></TextBox>
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Key="BooleanTemplate">
        <StackPanel Orientation="Horizontal">
            <Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>

            <ComboBox Width="100" SelectedIndex="{Binding Value.Item, Converter={StaticResource boolToIndexConverter}}">
                <ComboBoxItem Tag="1">True</ComboBoxItem>
                <ComboBoxItem Tag="0">False</ComboBoxItem>
            </ComboBox>
            <!--<TextBox Text="{Binding Value.Item}" Width="100" TextAlignment="Center"></TextBox>-->
        </StackPanel>
    </DataTemplate>
Niranjan NT
  • 165
  • 1
  • 19
  • 1
    See following posting. Use code a lot of times : http://stackoverflow.com/questions/28976601/recursion-parsing-xml-file-with-attributes-into-treeview-c-sharp – jdweng Jun 03 '16 at 12:18
  • Is it possible to write the logic in XAML using templates?? – Niranjan NT Jun 06 '16 at 04:11
  • The treeview can be XAML. The recursive code would add to the XAML. See following webpage for different types of treeviews : http://www.codeproject.com/Articles/124644/Basic-Understanding-of-Tree-View-in-WPF – jdweng Jun 06 '16 at 04:19

0 Answers0