<Page x:Class="GridTreeViewSamples.GridTreeViewSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c1="using:C1.Xaml"
    xmlns:flexgrid="using:C1.Xaml.FlexGrid">
    <Page.Resources>
        <Style TargetType="TextBlock" x:Key="title">
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Margin" Value="0 4 0 0" />
            <Setter Property="Foreground" Value="Black" />
        </Style>
        <Style TargetType="flexgrid:C1FlexGrid" >
            <Setter Property="RowBackground" Value="White" />
            <Setter Property="AlternatingRowBackground" Value="White" />
            <Setter Property="GroupRowBackground" Value="White" />
        </Style>
        <Style TargetType="c1:C1TreeViewItem" x:Key="itemContainerStyle">
            <Setter Property="IsExpanded" Value="True" />
        </Style>
    </Page.Resources>
    <Grid x:Name="LayoutRoot" >
        <Grid.Resources>
            <c1:C1HierarchicalDataTemplate x:Key="hierarchicalDataTemplate" ItemsSource="{Binding Children}">
                <c1:C1HierarchicalDataTemplate.Template>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </c1:C1HierarchicalDataTemplate.Template>
            </c1:C1HierarchicalDataTemplate>
            <c1:C1HierarchicalDataTemplate x:Key="topTemplate" ItemsSource="{Binding Children}" ItemTemplate="{StaticResource hierarchicalDataTemplate}">
                <c1:C1HierarchicalDataTemplate.Template>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </c1:C1HierarchicalDataTemplate.Template>
            </c1:C1HierarchicalDataTemplate>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto"/>
            <RowDefinition />
            <RowDefinition Height="auto"/>
            <RowDefinition />
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <!-- show time taken to create data -->
        <TextBlock x:Name="_txtPerson"  x:Uid="/GridTreeViewSamplesLib/Resources/Ready" Grid.ColumnSpan="2" Style="{StaticResource title}" />
        <!-- Bound TreeView -->
        <TextBlock x:Name="_txtTree" x:Uid="/GridTreeViewSamplesLib/Resources/Ready" Grid.Row="1" Style="{StaticResource title}" />

        <c1:C1TreeView x:Name="_tree" Grid.Row="2" ItemTemplate="{StaticResource topTemplate}" ItemContainerStyle="{StaticResource itemContainerStyle}">
        </c1:C1TreeView>
        
        <!-- Bound C1FlexGrid -->
        <TextBlock x:Name="_txtFlex" x:Uid="/GridTreeViewSamplesLib/Resources/Ready" Grid.Column="1" Grid.Row="1" Style="{StaticResource title}" />
        <flexgrid:C1FlexGrid x:Name="_flex" Grid.Column="1" Grid.Row="2" 
            AutoGenerateColumns="False" 
            ChildItemsPath="Children" >
            <flexgrid:C1FlexGrid.Columns>
                <flexgrid:Column x:Uid="/GridTreeViewSamplesLib/Resources/Name" Binding="{Binding Name, Mode=TwoWay}" Width="*" />
                <flexgrid:Column x:Uid="/GridTreeViewSamplesLib/Resources/Children" Binding="{Binding Children.Count}" />
            </flexgrid:C1FlexGrid.Columns>
        </flexgrid:C1FlexGrid>

        <!-- Unbound TreeView -->
        <TextBlock x:Name="_txtTreeUnbound" x:Uid="/GridTreeViewSamplesLib/Resources/Ready" Grid.Row="3" Style="{StaticResource title}" />
        <c1:C1TreeView x:Name="_treeUnbound" Grid.Row="4" ItemContainerStyle="{StaticResource itemContainerStyle}">
        </c1:C1TreeView>

        <!-- Unbound C1FlexGrid -->
        <TextBlock x:Name="_txtFlexUnbound" x:Uid="/GridTreeViewSamplesLib/Resources/Ready" Grid.Column="1" Grid.Row="3" Style="{StaticResource title}" />
        <flexgrid:C1FlexGrid x:Name="_flexUnbound" Grid.Column="1" Grid.Row="4" 
            AutoGenerateColumns="False" >
            <flexgrid:C1FlexGrid.Columns>
                <flexgrid:Column x:Uid="/GridTreeViewSamplesLib/Resources/Name" Binding="{Binding Name, Mode=TwoWay}" Width="*"/>
                <flexgrid:Column x:Uid="/GridTreeViewSamplesLib/Resources/Children" Binding="{Binding Children.Count}" Foreground="White"/>
            </flexgrid:C1FlexGrid.Columns>
        </flexgrid:C1FlexGrid>

        <!-- button bar -->
        <StackPanel Grid.Row="5" Grid.ColumnSpan="2" Orientation="Horizontal">
            <Button Name="_btnAddRoot" x:Uid="/GridTreeViewSamplesLib/Resources/AddRoot" Padding="12 0" Margin="4 2" Click="_btnAddRoot_Click" />
            <Button Name="_btnAddChild" x:Uid="/GridTreeViewSamplesLib/Resources/AddChild" Padding="12 0" Margin="4 2" Click="_btnAddChild_Click" />
            <Button Name="_btnDelete" x:Uid="/GridTreeViewSamplesLib/Resources/Delete" Padding="12 0" Margin="4 2" Click="_btnDelete_Click"/>
            <Button Name="_btnChange" x:Uid="/GridTreeViewSamplesLib/Resources/Change" Padding="12 0" Margin="4 2" Click="_btnChange_Click" />
        </StackPanel>
    </Grid>
</Page>
