I have a control populated with data like this
Label1
---Field1
---Field2
---Field3
Label2
---Field4
---Field5
---Field6
i have two buttons Next and Back. Now Field1 is selected on clicking Next i have to show Field2 as current selected item. After Field3 if i click Next current selected item should be Field4. vice versa when i click Back.
My treeview structure is like this
<TreeView x:Name="FieldTreeView" Grid.Row="1" BorderBrush="White" BorderThickness="0" ItemsSource="{Binding TreeDataSource}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type self:Labels}" ItemsSource="{Binding FieldName}" >
<TextBlock FontWeight="Bold" Text="{Binding Name}"/>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type self:Fields}">
<TextBlock Text="{Binding Field}" />
</DataTemplate>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
My class structure
public class Labels
{
public Labels()
{
this.FieldName = new List<Fields>();
}
public string Name { get; set; }
public List<Fields> FieldName { get; set; }
}
public class Fields
{
public string Field { get; set; }
}
Populating my data like this
List<Fields> fld = new List<Fields>();
fld.Add(new Fields() { Field = "Field1" });
fld.Add(new Fields() { Field = "Field2" });
fld.Add(new Fields() { Field = "Field3" });
List<Fields> fld1 = new List<Fields>();
fld1.Add(new Fields() { Field = "Field4" });
fld1.Add(new Fields() { Field = "Field5" });
fld1.Add(new Fields() { Field = "Field6" });
TreeDataSource.Add(new Labels() { Name = "Label1", FieldName = fld });
TreeDataSource.Add(new Labels() { Name = "Label2", FieldName = fld1 });
Can any one please help me on this.